6if (Loader::includeModule(
'replica'))
8 class StartWritingHandler
extends \Bitrix\Replica\Client\BaseHandler
10 protected $moduleId =
"im";
12 public function initDataManagerEvents()
14 \Bitrix\Main\EventManager::getInstance()->addEventHandler(
17 array($this,
"OnStartWriting")
19 \Bitrix\Main\EventManager::getInstance()->addEventHandler(
21 "OnExecuteStartWriting",
22 array($this,
"OnExecuteStartWriting")
26 function onStartWriting($params)
28 $userId = intval($params[
'USER_ID']);
34 if (\
Bitrix\Im\User::getInstance($userId)->isBot())
39 $dialogId = $params[
'DIALOG_ID'];
41 $operation = new \Bitrix\Replica\Db\Execute();
42 if (mb_substr($dialogId, 0, 4) ===
"chat")
44 $chatId = intval(mb_substr($dialogId, 4));
45 $operation->writeToLog(
49 "relation" =>
"b_user.ID",
56 "relation" =>
"b_im_chat.ID",
64 $dialogId = intval($dialogId);
65 $operation->writeToLog(
69 "relation" =>
"b_user.ID",
76 "relation" =>
"b_user.ID",
86 function onExecuteStartWriting(\
Bitrix\Main\Event $event)
88 $parameters = $event->getParameters();
89 $userId = intval($parameters[0]);
90 $dialogId = $parameters[1].$parameters[2];
94 if (!\
Bitrix\Main\Loader::includeModule(
'pull'))
97 $userName = \Bitrix\Im\User::getInstance($userId)->getFullName();
100 if (mb_substr($dialogId, 0, 4) ==
'chat')
102 $chatId = mb_substr($dialogId, 4);
103 $arRelation = \CIMChat::GetRelationById($chatId);
104 unset($arRelation[$userId]);
106 $chat = \Bitrix\Im\Model\ChatTable::getById($chatId);
107 $chatData = $chat->fetch();
109 $pullMessage = Array(
111 'command' =>
'startWriting',
114 'dialogId' => $dialogId,
116 'userName' => $userName
118 'extra' => \
Bitrix\Im\Common::getPullExtra()
120 if ($chatData[
'ENTITY_TYPE'] ==
'LINES')
122 foreach ($arRelation as $rel)
124 if ($rel[
"EXTERNAL_AUTH_ID"] ==
'imconnector')
126 unset($arRelation[$rel[
"USER_ID"]]);
130 \Bitrix\Pull\Event::add(array_keys($arRelation), $pullMessage);
132 $orm = \Bitrix\Im\Model\ChatTable::getById($chatId);
133 $chat = $orm->fetch();
134 if ($chat[
'TYPE'] == IM_MESSAGE_OPEN || $chat[
'TYPE'] == IM_MESSAGE_OPEN_LINE)
136 \CPullWatch::AddToStack(
'IM_PUBLIC_'.$chatId, $pullMessage);
139 else if (intval($dialogId) > 0)
141 \Bitrix\Pull\Event::add($dialogId, Array(
143 'command' =>
'startWriting',
146 'dialogId' => $userId,
148 'userName' => $userName
150 'extra' => \
Bitrix\Im\Common::getPullExtra()