Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chathandler.php
1<?php
2namespace Bitrix\Im\Replica;
3
5
6if (Loader::includeModule('replica'))
7{
8 class ChatHandler extends \Bitrix\Replica\Client\BaseHandler
9 {
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",
15 );
16 protected $predicates = array(
17 "AUTHOR_ID" => "b_user.ID",
18 );
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",
24 );
25 protected $children = array(
26 "ID" => "b_im_relation.CHAT_ID",
27 );
28 protected $fields = array(
29 "TITLE" => "text",
30 "DESCRIPTION" => "text",
31 "DATE_CREATE" => "datetime",
32 );
33
43 public function beforeInsertTrigger(array &$newRecord)
44 {
45 unset($newRecord["DISK_FOLDER_ID"]);
46 if (
47 isset($newRecord["TYPE"])
48 && $newRecord["TYPE"] === "S"
49 )
50 {
51 $chatList = \Bitrix\Im\Model\ChatTable::getList(array(
52 "filter" => array(
53 "=AUTHOR_ID" => $newRecord["AUTHOR_ID"],
54 "=TYPE" => "S",
55 ),
56 ));
57 $oldRecord = $chatList->fetch();
58 if ($oldRecord)
59 {
60 return $oldRecord;
61 }
62 }
63 return null;
64 }
65
74 public function beforeUpdateTrigger(array $oldRecord, array &$newRecord)
75 {
76 unset($newRecord["DISK_FOLDER_ID"]);
77 }
78
87 public function afterUpdateTrigger(array $oldRecord, array $newRecord)
88 {
89 if ($oldRecord['TITLE'] !== $newRecord['TITLE'])
90 {
91 if (\CModule::IncludeModule("pull"))
92 {
93 $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']);
94
95 $clearCacheOpen = false;
96 foreach ($ar as $rel)
97 {
98 if ($rel['MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
99 {
100 $clearCacheOpen = true;
101 }
102 else
103 {
104 \CIMContactList::CleanChatCache($rel['USER_ID']);
105 }
106
107 \Bitrix\Pull\Event::add($rel['USER_ID'], Array(
108 'module_id' => 'im',
109 'command' => 'chatRename',
110 'params' => Array(
111 'chatId' => $newRecord['CHAT_ID'],
112 'name' => $newRecord['TITLE'],
113 ),
114 'extra' => \Bitrix\Im\Common::getPullExtra()
115 ));
116 }
117 if ($clearCacheOpen)
118 {
119 \CIMContactList::CleanAllChatCache();
120 }
121 }
122 }
123 if ($oldRecord['AVATAR'] !== $newRecord['AVATAR'])
124 {
125 if (\CModule::IncludeModule('pull'))
126 {
127 $avatarImage = \CIMChat::GetAvatarImage($newRecord['AVATAR']);
128 $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']);
129
130 $clearCacheOpen = false;
131 foreach ($ar as $relation)
132 {
133 if ($relation['MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
134 {
135 $clearCacheOpen = true;
136 }
137 else
138 {
139 \CIMContactList::CleanChatCache($relation['USER_ID']);
140 }
141
142 \Bitrix\Pull\Event::add($relation['USER_ID'], Array(
143 'module_id' => 'im',
144 'command' => 'chatAvatar',
145 'params' => Array(
146 'chatId' => $newRecord['CHAT_ID'],
147 'avatar' => $avatarImage,
148 ),
149 'extra' => \Bitrix\Im\Common::getPullExtra()
150 ));
151 }
152 if ($clearCacheOpen)
153 {
154 \CIMContactList::CleanAllChatCache();
155 }
156 }
157 }
158 if ($oldRecord['COLOR'] !== $newRecord['COLOR'])
159 {
160 if (\CModule::IncludeModule('pull'))
161 {
162 $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']);
163
164 $clearCacheOpen = false;
165 foreach ($ar as $relation)
166 {
167 if ($relation['MESSAGE_TYPE'] == IM_MESSAGE_OPEN)
168 {
169 $clearCacheOpen = true;
170 }
171 else
172 {
173 \CIMContactList::CleanChatCache($relation['USER_ID']);
174 }
175
176 \Bitrix\Pull\Event::add($relation['USER_ID'], Array(
177 'module_id' => 'im',
178 'command' => 'chatChangeColor',
179 'params' => Array(
180 'chatId' => $newRecord['CHAT_ID'],
181 'color' => \Bitrix\Im\Color::getColor($newRecord['COLOR']),
182 ),
183 'extra' => \Bitrix\Im\Common::getPullExtra()
184 ));
185 }
186 if ($clearCacheOpen)
187 {
188 \CIMContactList::CleanAllChatCache();
189 }
190 }
191 }
192 }
193 }
194}