70 'data_type' =>
'integer',
72 'autocomplete' =>
true,
76 'data_type' =>
'integer',
79 'PARENT_MID' => array(
80 'data_type' =>
'integer',
84 'data_type' =>
'string',
85 'validation' => array(__CLASS__,
'validateTitle'),
87 'save_data_modification' => array(
'\Bitrix\Main\Text\Emoji',
'getSaveModificator'),
88 'fetch_data_modification' => array(
'\Bitrix\Main\Text\Emoji',
'getFetchModificator'),
90 'DESCRIPTION' => array(
91 'data_type' =>
'text',
93 'save_data_modification' => array(
'\Bitrix\Main\Text\Emoji',
'getSaveModificator'),
94 'fetch_data_modification' => array(
'\Bitrix\Main\Text\Emoji',
'getFetchModificator'),
97 'data_type' =>
'string',
98 'validation' => array(__CLASS__,
'validateColor'),
102 'data_type' =>
'string',
103 'validation' => array(__CLASS__,
'validateType'),
105 'default_value' =>
'C',
108 'data_type' =>
'boolean',
109 'values' => array(
'N',
'Y'),
111 'default_value' =>
'N',
113 'AUTHOR_ID' => array(
114 'data_type' =>
'integer',
119 'data_type' =>
'integer'
121 'CALL_TYPE' => array(
122 'data_type' =>
'integer',
125 'CALL_NUMBER' => array(
126 'data_type' =>
'string',
127 'validation' => array(__CLASS__,
'validateCallNumber'),
130 'ENTITY_TYPE' => array(
131 'data_type' =>
'string',
132 'validation' => array(__CLASS__,
'validateEntityType'),
135 'ENTITY_ID' => array(
136 'data_type' =>
'string',
137 'validation' => array(__CLASS__,
'validateEntityId'),
140 'ENTITY_DATA_1' => array(
141 'data_type' =>
'string',
142 'validation' => array(__CLASS__,
'validateEntityData'),
145 'ENTITY_DATA_2' => array(
146 'data_type' =>
'string',
147 'validation' => array(__CLASS__,
'validateEntityData'),
150 'ENTITY_DATA_3' => array(
151 'data_type' =>
'string',
152 'validation' => array(__CLASS__,
'validateEntityData'),
156 'data_type' =>
'Bitrix\Main\User',
157 'reference' => array(
'=this.AUTHOR_ID' =>
'ref.ID'),
159 'DISK_FOLDER_ID' => array(
160 'data_type' =>
'integer'
162 'PIN_MESSAGE_ID' => array(
163 'data_type' =>
'integer',
166 'MESSAGE_COUNT' => array(
167 'data_type' =>
'integer',
168 'default_value' => 0,
170 'USER_COUNT' => array(
171 'data_type' =>
'integer',
172 'default_value' => 0,
174 'PREV_MESSAGE_ID' => array(
175 'data_type' =>
'integer',
178 'LAST_MESSAGE_ID' => array(
179 'data_type' =>
'integer',
182 'LAST_MESSAGE_STATUS' => array(
183 'data_type' =>
'string',
184 'default_value' => IM_MESSAGE_STATUS_RECEIVED,
185 'validation' => array(__CLASS__,
'validateMessageStatus'),
187 'DATE_CREATE' => array(
188 'data_type' =>
'datetime',
190 'default_value' => array(__CLASS__,
'getCurrentDate'),
192 'MANAGE_USERS_ADD' => array(
193 'data_type' =>
'string',
196 'MANAGE_USERS_DELETE' => array(
197 'data_type' =>
'string',
200 'MANAGE_UI' => array(
201 'data_type' =>
'string',
204 'MANAGE_SETTINGS' => array(
205 'data_type' =>
'string',
209 'data_type' =>
'string',
213 'data_type' =>
'Bitrix\Im\Model\ChatIndex',
214 'reference' => array(
'=this.ID' =>
'ref.CHAT_ID'),
215 'join_type' =>
'INNER',
218 'data_type' =>
'Bitrix\ImOpenLines\Model\ChatIndexTable',
219 'reference' => array(
'=this.ID' =>
'ref.CHAT_ID'),
220 'join_type' =>
'INNER',
223 'data_type' =>
'Bitrix\Im\Model\AliasTable',
224 'reference' => array(
225 '=this.ID' =>
'ref.ENTITY_ID',
226 '=this.ENTITY_TYPE' =>
'ref.ENTITY_TYPE'
228 'join_type' =>
'LEFT',
230 'DISAPPEARING_TIME' => array(
231 'data_type' =>
'integer'
238 $fields = $event->getParameter(
"fields");
239 if (isset($fields[
'TITLE']))
241 $primary = $event->getParameter(
"id");
245 ->setChatId((
int)$primary[
"ID"])
247 static::updateIndexRecord($chatIndex);
250 $chatId = (int)$event->getParameter(
"id")[
'ID'];
251 if (static::needCacheInvalidate($fields))
258 Sync\Logger::getInstance()->add(
259 new Sync\
Event(Sync\Event::ADD_EVENT, Sync\Event::CHAT_ENTITY, $chatId),
264 return new Entity\EventResult();
269 $id = (int)$event->getParameter(
'primary')[
'ID'];
272 return new Entity\EventResult();
282 $record = static::getRecordChatData($chatIndex->
getChatId());
283 if(!is_array($record))
288 $chatIndex->
setTitle($record[
'TITLE']);
292 'SEARCH_CONTENT' => MapBuilder::create()->addText(self::generateSearchContent($chatIndex))->build(),
293 'SEARCH_TITLE' => MapBuilder::create()->addText(self::generateSearchTitle($chatIndex))->build(),
303 $insertData = self::prepareParamsForIndex($index);
305 ChatIndexTable::add($insertData);
310 $record = static::getRecordChatData($index->
getChatId());
311 if(!is_array($record))
318 if (Loader::includeModule(
'imopenlines'))
320 \Bitrix\ImOpenLines\Model\ChatIndexTable::updateIndex($index->
getChatId(), $record[
'TITLE'] ??
null);
327 $updateData = self::prepareParamsForIndex($index);
338 $cacheInvalidatingFields = [
353 'MANAGE_USERS_DELETE',
359 return !empty(array_intersect($cacheInvalidatingFields, array_keys($updatedFields)));
370 $userNameList = static::getChatUserNameList($chatIndex);
372 return $indexTitle .
' ' . implode(
' ', $userNameList);
383 new Entity\Validator\Length(
null, 255),
389 new Entity\Validator\Length(
null, 1),
395 new Entity\Validator\Length(
null, 255),
401 new Entity\Validator\Length(
null, 50),
407 new Entity\Validator\Length(
null, 255),
413 new Entity\Validator\Length(
null, 20),
419 new Entity\Validator\Length(
null, 255),
424 return new \Bitrix\Main\Type\DateTime();
429 new Entity\Validator\Length(
null, 50),
437 private static function getRecordChatData(
int $id)
446 ->whereNot(
'ENTITY_TYPE',
'LIVECHAT')
447 ->whereNull(
'ENTITY_TYPE')
454 private static function getChatUserNameList(ChatIndex $chatIndex): array
456 if (!$chatIndex->isEmptyUsers())
458 return $chatIndex->getClearedUserList();
462 \Bitrix\Im\Model\RelationTable::query()
463 ->addSelect(
'USER_ID')
464 ->where(
'CHAT_ID', $chatIndex->getChatId())
469 foreach ($query->exec() as $relation)
471 $rowUserName = \Bitrix\Im\User::getInstance($relation[
'USER_ID'])->getFullName(
false);
472 $clearedUsers[] = ChatIndex::clearText($rowUserName);
475 return $clearedUsers;
482 private static function prepareParamsForIndex(ChatIndex $index): array
485 'CHAT_ID' => $index->getChatId(),
486 'SEARCH_CONTENT' => MapBuilder::create()->addText(self::generateSearchContent($index))->build(),
487 'SEARCH_TITLE' => MapBuilder::create()->addText(self::generateSearchTitle($index))->build(),
static updateIndex($id, $primaryField, array $updateData)
static merge(array $data)
static validateMessageStatus()
static validateCallNumber()
static validateEntityData()
static validateEntityId()
static validateEntityType()
static generateSearchTitle(ChatIndex $chatIndex)
static generateSearchContent(ChatIndex $chatIndex)
static needCacheInvalidate(array $updatedFields)
static indexRecord(ChatIndex $chatIndex)
static onAfterDelete(Event $event)
static updateIndexRecord(ChatIndex $index)
static onAfterUpdate(\Bitrix\Main\ORM\Event $event)
static addIndexRecord(ChatIndex $index)
const MANAGE_RIGHTS_MEMBER
const MANAGE_RIGHTS_MANAGERS
const MANAGE_RIGHTS_OWNER
static cleanCache(int $id)
static getInstance(?int $chatId)