6if (Loader::includeModule(
'replica'))
8 class ChatHandler
extends \Bitrix\Replica\Client\BaseHandler
10 protected $tableName =
"b_im_chat";
11 protected $moduleId =
"im";
12 protected $className =
"\\Bitrix\\Im\\Model\\ChatTable";
13 protected $primary = array(
14 "ID" =>
"auto_increment",
16 protected $predicates = array(
17 "AUTHOR_ID" =>
"b_user.ID",
19 protected $translation = array(
20 "ID" =>
"b_im_chat.ID",
21 "AUTHOR_ID" =>
"b_user.ID",
22 "AVATAR" =>
"b_file.ID",
23 "LAST_MESSAGE_ID" =>
"b_im_message.ID",
25 protected $children = array(
26 "ID" =>
"b_im_relation.CHAT_ID",
28 protected $fields = array(
30 "DESCRIPTION" =>
"text",
31 "DATE_CREATE" =>
"datetime",
43 public function beforeInsertTrigger(array &$newRecord)
45 unset($newRecord[
"DISK_FOLDER_ID"]);
47 isset($newRecord[
"TYPE"])
48 && $newRecord[
"TYPE"] ===
"S"
51 $chatList = \Bitrix\Im\Model\ChatTable::getList(array(
53 "=AUTHOR_ID" => $newRecord[
"AUTHOR_ID"],
57 $oldRecord = $chatList->fetch();
74 public function beforeUpdateTrigger(array $oldRecord, array &$newRecord)
76 unset($newRecord[
"DISK_FOLDER_ID"]);
87 public function afterUpdateTrigger(array $oldRecord, array $newRecord)
89 if ($oldRecord[
'TITLE'] !== $newRecord[
'TITLE'])
91 if (\CModule::IncludeModule(
"pull"))
93 $ar = \CIMChat::GetRelationById($newRecord[
'CHAT_ID']);
95 $clearCacheOpen =
false;
98 if ($rel[
'MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
100 $clearCacheOpen =
true;
104 \CIMContactList::CleanChatCache($rel[
'USER_ID']);
107 \Bitrix\Pull\Event::add($rel[
'USER_ID'], Array(
109 'command' =>
'chatRename',
111 'chatId' => $newRecord[
'CHAT_ID'],
112 'name' => $newRecord[
'TITLE'],
114 'extra' => \
Bitrix\Im\Common::getPullExtra()
119 \CIMContactList::CleanAllChatCache();
123 if ($oldRecord[
'AVATAR'] !== $newRecord[
'AVATAR'])
125 if (\CModule::IncludeModule(
'pull'))
127 $avatarImage = \CIMChat::GetAvatarImage($newRecord[
'AVATAR']);
128 $ar = \CIMChat::GetRelationById($newRecord[
'CHAT_ID']);
130 $clearCacheOpen =
false;
131 foreach ($ar as $relation)
133 if ($relation[
'MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
135 $clearCacheOpen =
true;
139 \CIMContactList::CleanChatCache($relation[
'USER_ID']);
142 \Bitrix\Pull\Event::add($relation[
'USER_ID'], Array(
144 'command' =>
'chatAvatar',
146 'chatId' => $newRecord[
'CHAT_ID'],
147 'avatar' => $avatarImage,
149 'extra' => \
Bitrix\Im\Common::getPullExtra()
154 \CIMContactList::CleanAllChatCache();
158 if ($oldRecord[
'COLOR'] !== $newRecord[
'COLOR'])
160 if (\CModule::IncludeModule(
'pull'))
162 $ar = \CIMChat::GetRelationById($newRecord[
'CHAT_ID']);
164 $clearCacheOpen =
false;
165 foreach ($ar as $relation)
167 if ($relation[
'MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
169 $clearCacheOpen =
true;
173 \CIMContactList::CleanChatCache($relation[
'USER_ID']);
176 \Bitrix\Pull\Event::add($relation[
'USER_ID'], Array(
178 'command' =>
'chatChangeColor',
180 'chatId' => $newRecord[
'CHAT_ID'],
181 'color' => \
Bitrix\Im\Color::getColor($newRecord[
'COLOR']),
183 'extra' => \
Bitrix\Im\Common::getPullExtra()
188 \CIMContactList::CleanAllChatCache();