43 $messageType = $chatData[
"TYPE"] ?? $chatData[
"CHAT_TYPE"] ??
'';
44 $entityType = $chatData[
"ENTITY_TYPE"] ?? $chatData[
"CHAT_ENTITY_TYPE"] ??
'';
46 $messageType = trim($messageType);
47 $entityType = trim($entityType);
50 if (isset($chatData[
'ID']))
52 $chatId = (int)$chatData[
'ID'];
54 else if (isset($chatData[
'CHAT_ID']))
56 $chatId = (int)$chatData[
'CHAT_ID'];
59 if ($messageType == IM_MESSAGE_PRIVATE)
63 else if ($messageType === \
Bitrix\Im\V2\Chat::IM_TYPE_COPILOT)
67 else if (!empty($entityType))
70 $result = str_replace(
'_',
'', lcfirst(ucwords(mb_strtolower($entityType),
'_')));
72 else if ($chatId && $chatId === (
int)\CIMChat::GetGeneralChatId())
78 $result = $messageType == IM_MESSAGE_OPEN?
'open':
'chat';
81 return htmlspecialcharsbx($result);
86 $chatId = intval($chatId);
95 if (isset($params[
'SELECT']))
97 $params[
'SELECT'][] =
'ID';
98 $params[
'SELECT'][] =
'USER_ID';
99 $map = \Bitrix\Im\Model\RelationTable::getMap();
100 foreach ($params[
'SELECT'] as $key => $value)
102 if (is_int($key) && isset($map[$value]))
104 $selectFields .=
"R.{$value}, ";
107 else if (!is_int($key) && isset($map[$key]))
109 $value = (string)$value;
110 $selectFields .=
"R.{$key} '{$connection->getSqlHelper()->forSql($value)}', ";
117 $selectFields =
'R.*, ';
120 $withUserFields =
false;
121 if (isset($params[
'USER_DATA']) && $params[
'USER_DATA'] ==
'Y')
123 $withUserFields =
true;
124 $list = Array(
'ACTIVE',
'EXTERNAL_AUTH_ID');
125 foreach ($list as $key)
127 $selectFields .=
"U.{$key} USER_DATA_{$key}, ";
131 $skipUserInactiveSql =
'';
132 if (isset($params[
'SKIP_INACTIVE_USER']) && $params[
'SKIP_INACTIVE_USER'] ===
'Y')
135 $skipUserInactiveSql =
"AND U.ACTIVE = 'Y'";
138 $skipUserTypes = $params[
'SKIP_USER_TYPES'] ?? [];
139 if (isset($params[
'SKIP_CONNECTOR']) && $params[
'SKIP_CONNECTOR'] ===
'Y')
141 $skipUserTypes[] =
'imconnector';
144 $skipUserTypesSql =
'';
145 if (!empty($skipUserTypes))
148 if (count($skipUserTypes) === 1)
150 $skipUserTypesSql =
"AND (U.EXTERNAL_AUTH_ID != '".$connection->getSqlHelper()->forSql($skipUserTypes[0]).
"' OR U.EXTERNAL_AUTH_ID IS NULL)";
154 $skipUserTypes = array_map(
function($type) use ($connection) {
155 return $connection->getSqlHelper()->forSql($type);
158 $skipUserTypesSql =
"AND (U.EXTERNAL_AUTH_ID NOT IN ('".implode(
"','", $skipUserTypes).
"') OR U.EXTERNAL_AUTH_ID IS NULL)";
163 if (isset($params[
'FILTER']))
165 $map = \Bitrix\Im\Model\RelationTable::getMap();
166 foreach ($params[
'FILTER'] as $key => $value)
168 if (!isset($map[$key]))
176 else if (is_bool($value))
178 $value = $value?
"'Y'":
"'N'";
180 else if (is_string($value))
182 $value =
"'{$connection->getSqlHelper()->forSql($value)}'";
189 $whereFields .=
" AND R.{$key} = {$value}";
237 if (isset($params[
'LIMIT']))
239 $limit =
'LIMIT '.(int)$params[
'LIMIT'];
243 if (isset($params[
'OFFSET']))
245 $offset =
'OFFSET '.(int)$params[
'OFFSET'];
248 $orderField =
'R.ID';
250 if (isset($params[
'LAST_USER_ID']) && (int)$params[
'LAST_USER_ID'] >= 0)
252 $lastUserId = (int)$params[
'LAST_USER_ID'];
253 $whereFields .=
" AND R.USER_ID > {$lastUserId}";
254 $orderField =
'R.USER_ID';
257 $selectFields = rtrim($selectFields,
', ');
259 SELECT {$selectFields}
261 ".($withUserFields && !$skipUsers?
"LEFT JOIN b_user U ON R.USER_ID = U.ID":
"").
"
262 ".($skipUsers?
"INNER JOIN b_user U ON R.USER_ID = U.ID {$skipUserInactiveSql} {$skipUserTypesSql}":
"").
"
263 WHERE R.CHAT_ID = {$chatId} {$whereFields}
264 ORDER BY {$orderField} ASC
267 $relations = array();
268 $query = $connection->query($sql);
269 while ($row = $query->fetch())
298 foreach ($row as $key => $value)
300 if (mb_strpos($key,
'USER_DATA_') === 0)
302 $row[
'USER_DATA'][mb_substr($key, 10)] = $value;
307 $relations[$row[
'USER_ID']] = $row;
312 if (!isset($params[
'WITHOUT_COUNTERS']) || $params[
'WITHOUT_COUNTERS'] !==
'Y')
314 $userIds = array_keys($relations);
316 $counters = $readService->getCounterService()->getByChatForEachUsers($chatId, $userIds);
317 $lastIdInChat = $readService->getLastMessageIdInChat($chatId);
318 $lastReads = $readService->getViewedService()->getDateViewedByMessageIdForEachUser($lastIdInChat, $userIds);
319 foreach ($relations as $userId => $relation)
321 $counter = $counters[$userId] ?? 0;
322 $counter = $counter > 99 ? 100 : $counter;
323 $relations[$userId][
'COUNTER'] = $counter;
324 $relations[$userId][
'LAST_READ'] = $lastReads[$userId] ??
null;
332 public static function mute($chatId, $action, $userId =
null)
334 $userId = \Bitrix\Im\Common::getUserId($userId);
340 $chatId = intval($chatId);
346 $action = $action ===
true?
'Y':
'N';
348 (
new CounterService())->withContextUser($userId)->updateIsMuted($chatId, $action);
351 'SELECT' => Array(
'ID',
'MESSAGE_TYPE',
'NOTIFY_BLOCK',
'COUNTER'),
361 if ($relation[$userId][
'NOTIFY_BLOCK'] == $action)
366 \Bitrix\Im\Model\RelationTable::update($relation[$userId][
'ID'], array(
'NOTIFY_BLOCK' => $action));
371 if (\
Bitrix\Main\Loader::includeModule(
'pull'))
373 $element = \Bitrix\Im\Model\RecentTable::getList([
374 'select' => [
'USER_ID',
'ITEM_TYPE',
'ITEM_ID',
'UNREAD'],
376 '=USER_ID' => $userId,
377 '=ITEM_TYPE' => $relation[$userId][
'MESSAGE_TYPE'],
378 '=ITEM_ID' => $chatId
382 $counter = $relation[$userId][
'COUNTER'];
384 \Bitrix\Pull\Event::add($userId, Array(
386 'command' =>
'chatMuteNotify',
389 'dialogId' =>
'chat'.$chatId,
390 'muted' => $action ==
'Y',
391 'mute' => $action ==
'Y',
392 'counter' => $counter,
393 'lines' => $element[
'ITEM_TYPE'] === self::TYPE_OPEN_LINE,
394 'unread' => ($element[
'UNREAD'] ??
'N') ===
'Y',
400 $chat = \Bitrix\Im\Chat::getById($chatId);
403 ExecuteModuleEventEx($event, [[
404 'CHAT_ID' => $chatId,
405 'USER_ID' => $userId,
406 'MUTE' => $action ==
'Y',
416 $chatId = intval($chatId);
422 $userId = \Bitrix\Im\Common::getUserId($userId);
428 $relationData = \Bitrix\Im\Model\RelationTable::getList(Array(
429 'select' => Array(
'START_ID'),
430 'filter' => Array(
'=CHAT_ID' => $chatId,
'=USER_ID' => $userId)
433 if (!$relationData || $relationData[
'START_ID'] == 0)
435 $counter = \Bitrix\Im\Model\MessageTable::getCount([
'=CHAT_ID' => $chatId]);
439 $counter = \Bitrix\Im\Model\MessageTable::getCount([
'=CHAT_ID' => $chatId,
'>=ID' => $relationData[
'START_ID']]);
442 return $counter > 0 ? $counter : 0;
462 public static function getMessages($chatId, $userId =
null, $options = Array())
464 $userId = \Bitrix\Im\Common::getUserId($userId);
470 $chatData = \Bitrix\Im\Model\ChatTable::getList(Array(
473 'CHAT_TYPE' =>
'TYPE',
474 'CHAT_ENTITY_TYPE' =>
'ENTITY_TYPE',
475 'CHAT_ENTITY_ID' =>
'ENTITY_ID',
476 'RELATION_USER_ID' =>
'RELATION.USER_ID',
477 'RELATION_START_ID' =>
'RELATION.START_ID',
479 'RELATION_LAST_ID' =>
'RELATION.LAST_ID',
483 'filter' => Array(
'=ID' => $chatId),
487 '\Bitrix\Im\Model\RelationTable',
489 "=ref.CHAT_ID" =>
"this.ID",
492 array(
"join_type"=>
"LEFT")
503 $chatData[
'RELATION_UNREAD_ID'] = $readService->getCounterService()->getIdFirstUnreadMessage($chatId) ?? 0;
504 $chatData[
'RELATION_COUNTER'] = $readService->getCounterService()->getByChat($chatId);
505 $chatData[
'RELATION_START_ID'] = (int)$chatData[
'RELATION_START_ID'];
507 if (isset($options[
'LIMIT']))
509 $options[
'LIMIT'] = intval($options[
'LIMIT']);
510 $limit = $options[
'LIMIT'] >= 100? 100: $options[
'LIMIT'];
518 '=CHAT_ID' => $chatId
522 $startFromUnread =
false;
524 !isset($options[
'LAST_ID'])
525 && !isset($options[
'FIRST_ID'])
527 && $chatData[
'RELATION_COUNTER'] > 0
530 if ($chatData[
'RELATION_COUNTER'] > $limit)
532 $startFromUnread =
true;
533 $options[
'FIRST_ID'] = $chatData[
'RELATION_LAST_ID'];
537 $limit += $chatData[
'RELATION_COUNTER'];
541 if (isset($options[
'FIRST_ID']))
546 if ($chatData[
'RELATION_START_ID'] > 0 && intval($options[
'FIRST_ID']) < $chatData[
'RELATION_START_ID'])
548 $filter[
'>=ID'] = $chatData[
'RELATION_START_ID'];
552 if (intval($options[
'FIRST_ID']) > 0)
554 $filter[
'>ID'] = $options[
'FIRST_ID'];
561 $orderId = Array(
'CHAT_ID' =>
'ASC',
'ID' =>
'DESC');
562 $orderResult = Array(
'ID' =>
'DESC');
564 if ($chatData[
'RELATION_START_ID'] > 0)
566 $filter[
'>=ID'] = $chatData[
'RELATION_START_ID'];
569 if (isset($options[
'LAST_ID']) && intval($options[
'LAST_ID']) > 0)
571 $filter[
'<ID'] = intval($options[
'LAST_ID']);
575 $orm = \Bitrix\Im\Model\MessageTable::getList(array(
581 $ids = array_map(fn ($item) => $item[
'ID'], $orm->fetchAll());
585 'CHAT_ID' => (int)$chatId,
590 if ($options[
'JSON'])
592 $result = array_change_key_case($result, CASE_LOWER);
597 $orm = \Bitrix\Im\Model\MessageTable::getList(array(
599 'ID',
'AUTHOR_ID',
'DATE_CREATE',
'NOTIFY_EVENT',
'MESSAGE',
600 'USER_LAST_ACTIVITY_DATE' =>
'AUTHOR.LAST_ACTIVITY_DATE',
604 'MESSAGE_UUID' =>
'UUID.UUID',
606 'filter' => [
'=ID' => $ids],
607 'order' => $orderResult,
612 $userOptions = [
'SKIP_ONLINE' =>
'Y'];
613 if ($options[
'JSON'] ==
'Y')
615 $userOptions[
'JSON'] =
'Y';
617 if ($chatData[
'CHAT_ENTITY_TYPE'] ==
'LIVECHAT')
619 [$lineId] = explode(
'|', $chatData[
'CHAT_ENTITY_ID']);
620 $userOptions[
'LIVECHAT'] = $lineId;
621 $userOptions[
'USER_CODE'] =
'livechat|' . $lineId .
'|' . $chatData[
'CHAT_ID'] .
'|' . $userId;
625 while($message = $orm->fetch())
627 if ($message[
'NOTIFY_EVENT'] ==
'private_system')
629 $message[
'AUTHOR_ID'] = 0;
632 if (isset($options[
'USER_TAG_SPREAD']) && $options[
'USER_TAG_SPREAD'] ===
'Y')
634 $message[
'MESSAGE'] = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", Array(
'\Bitrix\Im\Text',
'modifyShortUserTag'), $message[
'MESSAGE']);
637 $messages[$message[
'ID']] = Array(
638 'ID' => (
int)$message[
'ID'],
639 'CHAT_ID' => (
int)$chatId,
640 'AUTHOR_ID' => (
int)$message[
'AUTHOR_ID'],
641 'DATE' => $message[
'DATE_CREATE'],
643 'UNREAD' => $chatData[
'RELATION_USER_ID'] > 0 && $chatData[
'RELATION_LAST_ID'] < $message[
'ID'],
644 'UUID' => $message[
'MESSAGE_UUID'],
646 $messages[$message[
'ID']][
'REPLACES'] = \Bitrix\Im\Text::getReplaceMap($messages[$message[
'ID']][
'TEXT']);
647 if ($message[
'AUTHOR_ID'] && !isset($users[$message[
'AUTHOR_ID']]))
650 $user[
'last_activity_date'] = $message[
'USER_LAST_ACTIVITY_DATE']? date(
'c', $message[
'USER_LAST_ACTIVITY_DATE']->getTimestamp()):
false;
651 $user[
'desktop_last_date'] =
false;
652 $user[
'mobile_last_date'] =
false;
653 $user[
'idle'] =
false;
655 $users[$message[
'AUTHOR_ID']] = $user;
657 if ($options[
'CONVERT_TEXT'])
659 $messages[$message[
'ID']][
'TEXT_CONVERTED'] = \Bitrix\Im\Text::parseLegacyFormat($message[
'MESSAGE']);
663 $params = \CIMMessageParam::Get(array_keys($messages));
666 foreach ($params as $messageId => $param)
668 $messages[$messageId][
'PARAMS'] = empty($param)? []: $param;
671 empty($messages[$messageId][
'TEXT'])
672 && !isset($param[
'FILE_ID'])
673 && !isset($param[
'KEYBOARD'])
674 && !isset($param[
'ATTACH'])
677 $messages[$messageId][
'TEXT'] =
Loc::getMessage(
'IM_CHAT_MESSAGE_DELETED');
678 $messages[$messageId][
'PARAMS'][
'IS_DELETED'] =
'Y';
681 if (isset($param[
'FILE_ID']))
683 foreach ($param[
'FILE_ID'] as $fileId)
685 $fileIds[$fileId] = $fileId;
689 if (isset($param[
'CHAT_USER']) && is_array($param[
'CHAT_USER']))
691 foreach ($param[
'CHAT_USER'] as $paramsUserId)
693 $users[$paramsUserId] =
User::getInstance($paramsUserId)->getArray($userOptions);
699 foreach ($messages as $messageId => $message)
702 isset($disappearing[$messageId])
703 && $disappearing[$messageId][
'DATE_REMOVE'] instanceof
DateTime
706 $messages[$messageId][
'DISAPPEARING_DATE'] = $disappearing[$messageId][
'DATE_REMOVE']->format(DATE_ATOM);
710 $messages[$messageId][
'DISAPPEARING_DATE'] =
null;
714 $messages = \CIMMessageLink::prepareShow($messages, $params);
716 $files = \CIMDisk::GetFiles($chatId, $fileIds);
719 'CHAT_ID' => (
int)$chatId,
720 'MESSAGES' => $messages,
721 'USERS' => array_values($users),
722 'FILES' => array_values($files),
725 if (count($files) && $fileSort ==
'DESC')
727 $result[
'FILES'] = array_reverse($result[
'FILES']);
730 if ($startFromUnread)
732 $result[
'MESSAGES'] = array_reverse($result[
'MESSAGES']);
735 'LAST_ID' => $chatData[
'RELATION_UNREAD_ID']
737 $result[
'MESSAGES'] = array_merge($result[
'MESSAGES'], $additionalMessages[
'MESSAGES']);
740 if ($options[
'JSON'])
742 foreach ($result[
'MESSAGES'] as $key => $value)
746 $result[
'MESSAGES'][$key][
'DATE'] = date(
'c', $value[
'DATE']->getTimestamp());
749 if (isset($value[
'PARAMS'][
'CHAT_LAST_DATE']) && $value[
'PARAMS'][
'CHAT_LAST_DATE'] instanceof \
Bitrix\Main\
Type\
DateTime)
751 $result[
'MESSAGES'][$key][
'PARAMS'][
'CHAT_LAST_DATE'] = date(
'c', $value[
'PARAMS'][
'CHAT_LAST_DATE']->getTimestamp());
754 if (is_array($value[
'REPLACES']) && !empty($value[
'REPLACES']))
756 $result[
'MESSAGES'][$key][
'REPLACES'] =
Common::toJson($value[
'REPLACES']);
759 $result[
'MESSAGES'][$key] = array_change_key_case($result[
'MESSAGES'][$key], CASE_LOWER);
761 $result[
'MESSAGES'] = array_values($result[
'MESSAGES']);
763 foreach ($result[
'FILES'] as $key => $value)
767 $result[
'FILES'][$key][
'date'] = date(
'c', $value[
'date']->getTimestamp());
770 foreach ([
'urlPreview',
'urlShow',
'urlDownload'] as $field)
772 $url = $result[
'FILES'][$key][$field];
773 if (is_string($url) && $url && mb_strpos($url,
'http') !== 0)
775 $result[
'FILES'][$key][$field] = \Bitrix\Im\Common::getPublicDomain().$url;
781 $result = array_change_key_case($result, CASE_LOWER);
787 public static function getUsers($chatId, $options = []): array
790 'SELECT' => [
'ID',
'USER_ID'],
791 'SKIP_INACTIVE_USER' =>
'Y',
792 'WITHOUT_COUNTERS' =>
'Y',
795 $skipExternal = isset($options[
'SKIP_EXTERNAL']) || isset($options[
'SKIP_EXTERNAL_EXCEPT_TYPES']);
798 $exceptType = $options[
'SKIP_EXTERNAL_EXCEPT_TYPES'] ?? [];
799 $params[
'SKIP_USER_TYPES'] = \Bitrix\Im\Model\UserTable::filterExternalUserTypes($exceptType);
802 if (isset($options[
'LIMIT']))
804 $params[
'LIMIT'] = $options[
'LIMIT'];
806 if (isset($options[
'OFFSET']))
808 $params[
'OFFSET'] = $options[
'OFFSET'];
810 if (isset($options[
'LAST_ID']))
812 $params[
'LAST_USER_ID'] = (int)$options[
'LAST_ID'];
815 $json = isset($options[
'JSON']) && $options[
'JSON'] ===
'Y' ?
'Y' :
'N';
818 foreach ($relations as $user)
820 $userData = \Bitrix\Im\User::getInstance($user[
'USER_ID'])->getArray([
824 if ($userData[
'bot'])
826 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_LOWER | Converter::KEYS);
828 $botData = \Bitrix\Im\V2\Entity\User\Data\BotData::getInstance((
int)$user[
'USER_ID'])->toRestFormat();
829 $userData[
'bot_data'] = (!empty($botData)) ? $converter->process($botData) :
null;
833 $userData[
'bot_data'] =
null;
836 $users[] = $userData;
851 public static function getById($id, $params = array())
853 $userId = \Bitrix\Im\Common::getUserId();
859 $checkAccessParam = $params[
'CHECK_ACCESS'] ??
null;
861 'FILTER' => Array(
'ID' => $id),
862 'SKIP_ACCESS_CHECK' => $checkAccessParam ===
'Y'?
'N':
'Y',
873 if (isset($params[
'LOAD_READED']) && $params[
'LOAD_READED'])
875 $userOptions = [
'SKIP_ONLINE' =>
'Y'];
876 if ($chat[
'ENTITY_TYPE'] ==
'LIVECHAT')
878 [$lineId] = explode(
'|', $chat[
'CHAT_ENTITY_ID']);
879 $userOptions[
'LIVECHAT'] = $lineId;
880 $userOptions[
'USER_CODE'] =
'livechat|' . $lineId .
'|' . $id .
'|' . $userId;
885 $chat[
'READED_LIST'] = [];
886 $chat[
'MANAGER_LIST'] = [];
887 foreach ($relations as $relation)
890 $relation[
'USER_ID'] != $userId
895 $user = \Bitrix\Im\User::getInstance($relation[
'USER_ID'])->getArray($userOptions);
896 $chat[
'READED_LIST'][] = [
897 'USER_ID' => (int)$relation[
'USER_ID'],
898 'USER_NAME' => $user[
'NAME'],
899 'MESSAGE_ID' => (
int)$relation[
'LAST_ID'],
900 'DATE' => $relation[
'LAST_READ'],
904 if ($relation[
'MANAGER'] ===
'Y')
906 $chat[
'MANAGER_LIST'][] = (int)$relation[
'USER_ID'];
912 $chatInstance = \Bitrix\Im\V2\Chat::getInstance((
int)$id);
913 $chat[
'LAST_MESSAGE_VIEWS'] = $chatInstance->getLastMessageViews();
918 if ($params[
'JSON'] ??
null)
926 public static function getList($params = array())
928 $params = is_array($params)? $params: Array();
930 if (!isset($params[
'CURRENT_USER']) && is_object(
$GLOBALS[
'USER']))
932 $params[
'CURRENT_USER'] =
$GLOBALS[
'USER']->GetID();
935 $params[
'CURRENT_USER'] = intval($params[
'CURRENT_USER']);
937 $params[
'SKIP_ACCESS_CHECK'] = $params[
'SKIP_ACCESS_CHECK'] ===
'Y'?
'Y':
'N';
939 $userId = $params[
'CURRENT_USER'];
945 $enableLimit =
false;
946 if (isset($params[
'OFFSET']))
948 $filterLimit = intval($params[
'LIMIT']);
951 $filterOffset = intval($params[
'OFFSET']);
957 $filterLimit =
false;
958 $filterOffset =
false;
968 $ormParams[
'offset'] = $filterOffset;
969 $ormParams[
'limit'] = $filterLimit;
971 if (isset($params[
'ORDER']))
973 $ormParams[
'order'] = $params[
'ORDER'];
976 $orm = \Bitrix\Im\Model\ChatTable::getList($ormParams);
977 $chatsRaw = $orm->fetchAll();
981 foreach ($chatsRaw as $chatRaw)
986 if (isset($params[
'JSON']) && $params[
'JSON'])
996 $generalChatId = \CIMChat::GetGeneralChatId();
997 $avatar = \CIMChat::GetAvatarImage($chat[
'AVATAR'], 200,
false);
1000 if ($generalChatId == $chat[
'ID'])
1002 $chat[
"ENTITY_TYPE"] =
'GENERAL';
1005 $chatType = \Bitrix\Im\Chat::getType($chat);
1007 $muteList = Array();
1008 if ($chat[
'RELATION_NOTIFY_BLOCK'] ==
'Y')
1010 $muteList[] = (int)$chat[
'RELATION_USER_ID'];
1013 $counter = (int)$chat[
'RELATION_COUNTER'];
1014 $startCounter = (int)$chat[
'RELATION_START_COUNTER'];
1015 $userCounter = (int)$chat[
'USER_COUNT'];
1016 $unreadId = (int)$chat[
'RELATION_UNREAD_ID'];
1017 $lastMessageId = (int)$chat[
'LAST_MESSAGE_ID'];
1020 if ($chat[
'ALIAS_NAME'])
1023 'code' => $chat[
'ALIAS_NAME'],
1028 $options = \CIMChat::GetChatOptions();
1029 $restrictions = $options[
'DEFAULT'];
1031 if ($chat[
"ENTITY_TYPE"] && in_array($chat[
"ENTITY_TYPE"], array_keys($options),
true))
1033 $restrictions = $options[$chat[
'ENTITY_TYPE']];
1037 'ID' => (
int)$chat[
'ID'],
1038 'NAME' => $chat[
'TITLE'],
1039 'DESCRIPTION' => $chat[
'DESCRIPTION'],
1040 'OWNER' => (
int)$chat[
'AUTHOR_ID'],
1041 'EXTRANET' => $chat[
'EXTRANET'] ==
'Y',
1042 'AVATAR' => $avatar,
1044 'TYPE' => $chatType,
1045 'COUNTER' => $counter,
1046 'USER_COUNTER' => $userCounter,
1047 'MESSAGE_COUNT' => (
int)$chat[
'MESSAGE_COUNT'] - $startCounter,
1048 'UNREAD_ID' => $unreadId,
1049 'RESTRICTIONS' => $restrictions,
1050 'LAST_MESSAGE_ID' => $lastMessageId,
1051 'LAST_ID' => (
int)$chat[
'RELATION_LAST_ID'],
1052 'MARKED_ID' => (
int)$chat[
'MARKED_ID'],
1053 'DISK_FOLDER_ID' => (
int)$chat[
'DISK_FOLDER_ID'],
1054 'ENTITY_TYPE' => (
string)$chat[
'ENTITY_TYPE'],
1055 'ENTITY_ID' => (
string)$chat[
'ENTITY_ID'],
1056 'ENTITY_DATA_1' => (
string)$chat[
'ENTITY_DATA_1'],
1057 'ENTITY_DATA_2' => (
string)$chat[
'ENTITY_DATA_2'],
1058 'ENTITY_DATA_3' => (
string)$chat[
'ENTITY_DATA_3'],
1059 'MUTE_LIST' => $muteList,
1060 'DATE_CREATE' => $chat[
'DATE_CREATE'],
1061 'MESSAGE_TYPE' => $chat[
"TYPE"],
1062 'DISAPPEARING_TIME' => (
int)$chat[
'DISAPPEARING_TIME'],
1063 'PUBLIC' => $publicOption,
1064 'ROLE' => mb_strtolower(self::getRole($chat)),
1066 'AI_PROVIDER' => $chatType ===
'copilot' ? AIHelper::getProviderName() :
null,
1068 'MANAGE_USERS_ADD' => mb_strtolower((
string)$chat[
'MANAGE_USERS_ADD']),
1069 'MANAGE_USERS_DELETE' => mb_strtolower((
string)$chat[
'MANAGE_USERS_DELETE']),
1070 'MANAGE_UI' => mb_strtolower((
string)$chat[
'MANAGE_UI']),
1071 'MANAGE_SETTINGS' => mb_strtolower((
string)$chat[
'MANAGE_SETTINGS']),
1072 'CAN_POST' => mb_strtolower((
string)$chat[
'CAN_POST']),
1079 if (!isset($params[
'CURRENT_USER']) && is_object(
$GLOBALS[
'USER']))
1081 $params[
'CURRENT_USER'] =
$GLOBALS[
'USER']->GetID();
1084 $params[
'CURRENT_USER'] = intval($params[
'CURRENT_USER']);
1086 $userId = $params[
'CURRENT_USER'];
1096 $field =
'*INDEX.SEARCH_CONTENT';
1098 if (isset($params[
'FILTER'][
'SEARCH']))
1100 $find = (string)$params[
'FILTER'][
'SEARCH'];
1102 elseif (isset($params[
'FILTER'][
'SEARCH_OL']) && Loader::includeModule(
'imopenlines'))
1104 $find = (string)$params[
'FILTER'][
'SEARCH_OL'];
1105 $field =
'*OL_INDEX.SEARCH_TITLE';
1108 if (isset($params[
'FILTER'][
'ID']))
1110 $filter[
'=ID'] = $params[
'FILTER'][
'ID'];
1112 else if (isset($find))
1115 if (Model\ChatIndexTable::getEntity()->fullTextIndexEnabled(
'SEARCH_CONTENT'))
1117 $find = trim($find);
1118 $find = \Bitrix\Main\Search\Content::prepareStringToken($find);
1120 if (\
Bitrix\Main\Search\Content::canUseFulltextSearch($find, \
Bitrix\Main\Search\Content::TYPE_MIXED))
1122 $filter[$field] = $find;
1131 if (mb_strlen($find) < 3)
1136 $filter[
'%=INDEX.SEARCH_TITLE'] = $helper->forSql($find).
'%';
1140 if ($params[
'SKIP_ACCESS_CHECK'] ===
'Y')
1149 $filter[
'=TYPE'] = [
1155 if (
User::getInstance($params[
'CURRENT_USER'])->isBot() && Loader::includeModule(
'imopenlines'))
1161 '=RELATION.USER_ID' => $params[
'CURRENT_USER']
1164 '=RECENT_OL.USER_ID' => $params[
'CURRENT_USER']
1170 $filter[
'=RELATION.USER_ID'] = $params[
'CURRENT_USER'];
1182 '=RELATION.USER_ID' => $params[
'CURRENT_USER']
1186 '=RELATION.USER_ID' => $params[
'CURRENT_USER']
1190 '=RELATION.USER_ID' => $params[
'CURRENT_USER']
1194 '=RELATION.USER_ID' => $params[
'CURRENT_USER']
1197 if (Loader::includeModule(
'imopenlines'))
1201 '=RECENT_OL.USER_ID' => $params[
'CURRENT_USER']
1204 $filter[] = $condition;
1207 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1209 'Bitrix\Im\Model\RelationTable',
1211 "=ref.CHAT_ID" =>
"this.ID",
1214 array(
"join_type"=>
"LEFT")
1216 if (Loader::includeModule(
'imopenlines'))
1218 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1220 \
Bitrix\ImOpenLines\Model\RecentTable::class,
1222 "=ref.CHAT_ID" =>
"this.ID",
1225 array(
"join_type"=>
"LEFT")
1232 'RELATION_USER_ID' =>
'RELATION.USER_ID',
1233 'RELATION_MANAGER' =>
'RELATION.MANAGER',
1234 'RELATION_NOTIFY_BLOCK' =>
'RELATION.NOTIFY_BLOCK',
1236 'RELATION_START_COUNTER' =>
'RELATION.START_COUNTER',
1237 'RELATION_LAST_ID' =>
'RELATION.LAST_ID',
1240 'ALIAS_NAME' =>
'ALIAS.ALIAS',
1242 'filter' => $filter,
1243 'runtime' => $runtime
1329 $chatOptions = \CIMChat::GetChatOptions();
1330 $isAllowedByDefault = (bool)($chatOptions[
'DEFAULT'][$action] ??
true);
1332 if ($entityType && $chatOptions[$entityType])
1334 return (
bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
1339 return $isAllowedByDefault;
1342 $chatId = \Bitrix\Im\Dialog::getChatId($dialogId);
1345 return $isAllowedByDefault;
1348 $generalChatId = (int)\CIMChat::GetGeneralChatId();
1349 if ($chatId === $generalChatId)
1351 return (
bool)($chatOptions[
'GENERAL'][$action] ?? $isAllowedByDefault);
1354 $chat = \Bitrix\Im\Model\ChatTable::getList([
1364 $entityType = ($chat && $chat[
'ENTITY_TYPE']) ? $chat[
'ENTITY_TYPE'] :
null;
1366 if ($entityType && $chatOptions[$entityType])
1368 return (
bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
1371 return $isAllowedByDefault;
1413 $userId = \Bitrix\Im\Common::getUserId();
1418 foreach ($chats as $chat)
1420 $chatIds[] = (int)$chat[
'ID'];
1423 $counters = $readService->getCounterService()->getForEachChat($chatIds);
1424 $unreadIds = $readService->getCounterService()->getIdFirstUnreadMessageForEachChats($chatIds);
1427 foreach ($chats as $key => $chat)
1429 $id = (int)$chat[
'ID'];
1430 $chats[$key][
'RELATION_COUNTER'] = $counters[$id] ?? 0;
1431 $chats[$key][
'RELATION_UNREAD_ID'] = $unreadIds[$id] ?? 0;
1432 $chats[$key][
'MARKED_ID'] = $markedIds[$id] ?? 0;