4use Bitrix\Im\Model\BlockUserTable;
5use Bitrix\Im\V2\Chat\Background\Background;
6use Bitrix\Im\V2\Chat\EntityLink;
7use Bitrix\Im\V2\Chat\ExtendedType;
8use Bitrix\Im\V2\Chat\GeneralChannel;
9use Bitrix\Im\V2\Chat\GeneralChat;
10use Bitrix\Im\V2\Chat\TextField\TextFieldEnabled;
11use Bitrix\Im\V2\Message\CounterService;
12use Bitrix\Im\V2\Message\Delete\DisappearService;
13use Bitrix\Im\V2\Message\ReadService;
14use Bitrix\Main\Application;
15use Bitrix\Main\Engine\Response\Converter;
16use Bitrix\Main\Loader;
17use Bitrix\Main\Localization\Loc;
18use Bitrix\Main\Type\DateTime;
20Loc::loadMessages(__FILE__);
42 return \CIMChat::getGroupTypes();
45 public static function getType($chatData,
bool $camelCase =
true)
47 $messageType = $chatData[
"TYPE"] ?? $chatData[
"CHAT_TYPE"] ??
'';
48 $entityType = $chatData[
"ENTITY_TYPE"] ?? $chatData[
"CHAT_ENTITY_TYPE"] ??
'';
49 $chatId = $chatData[
'ID'] ?? $chatData[
'CHAT_ID'] ??
null;
51 $messageType = trim($messageType);
52 $entityType = trim($entityType);
54 $type = ExtendedType::tryFromTypeLiteral($messageType);
58 self::isGeneralChannel($chatId, $messageType, $entityType) => ExtendedType::GeneralChannel->value,
59 self::isGeneralChat($chatId, $messageType, $entityType) => ExtendedType::General->value,
60 !in_array(
$type, [ExtendedType::Chat, ExtendedType::OpenChat],
true) =>
$type->value,
61 !empty($entityType) => $entityType,
62 default =>
$type->value,
73 protected static function isGeneralChat(?
int $chatId,
string $typeLiteral,
string $entityType): bool
76 ExtendedType::tryFromTypeLiteral($typeLiteral) === ExtendedType::OpenChat
77 && ExtendedType::tryFromEntityType($entityType) === ExtendedType::General
83 protected static function isGeneralChannel(?
int $chatId,
string $typeLiteral,
string $entityType): bool
86 ExtendedType::tryFromTypeLiteral($typeLiteral) === ExtendedType::OpenChannel
87 && ExtendedType::tryFromEntityType($entityType) === ExtendedType::GeneralChannel
95 $chatId = intval($chatId);
107 $params[
'SELECT'][] =
'USER_ID';
111 if (is_int(
$key) && isset(
$map[$value]))
118 $value = (string)$value;
119 $selectFields .=
"R.{$key} '{$connection->getSqlHelper()->forSql($value)}', ";
129 $withUserFields =
false;
132 $withUserFields =
true;
133 $list = Array(
'ACTIVE',
'EXTERNAL_AUTH_ID');
134 foreach ($list as
$key)
140 $skipUserInactiveSql =
'';
141 if (isset(
$params[
'SKIP_INACTIVE_USER']) &&
$params[
'SKIP_INACTIVE_USER'] ===
'Y')
144 $skipUserInactiveSql =
"AND U.ACTIVE = 'Y'";
147 $skipUserTypes =
$params[
'SKIP_USER_TYPES'] ?? [];
148 if (isset(
$params[
'SKIP_CONNECTOR']) &&
$params[
'SKIP_CONNECTOR'] ===
'Y')
150 $skipUserTypes[] =
'imconnector';
153 $skipUserTypesSql =
'';
154 if (!empty($skipUserTypes))
157 if (
count($skipUserTypes) === 1)
159 $skipUserTypesSql =
"AND (U.EXTERNAL_AUTH_ID != '".$connection->getSqlHelper()->forSql($skipUserTypes[0]).
"' OR U.EXTERNAL_AUTH_ID IS NULL)";
167 $skipUserTypesSql =
"AND (U.EXTERNAL_AUTH_ID NOT IN ('".implode(
"','", $skipUserTypes).
"') OR U.EXTERNAL_AUTH_ID IS NULL)";
185 else if (is_bool($value))
187 $value = $value?
"'Y'":
"'N'";
189 else if (is_string($value))
191 $value =
"'{$connection->getSqlHelper()->forSql($value)}'";
198 $whereFields .=
" AND R.{$key} = {$value}";
205 $limit =
'LIMIT '.(int)
$params[
'LIMIT'];
211 $offset =
'OFFSET '.(int)
$params[
'OFFSET'];
214 $orderField =
'R.ID';
216 if (isset(
$params[
'LAST_USER_ID']) && (
int)
$params[
'LAST_USER_ID'] >= 0)
218 $lastUserId = (int)
$params[
'LAST_USER_ID'];
219 $whereFields .=
" AND R.USER_ID > {$lastUserId}";
220 $orderField =
'R.USER_ID';
225 SELECT {$selectFields}
227 ".($withUserFields && !$skipUsers?
"LEFT JOIN b_user U ON R.USER_ID = U.ID":
"").
"
228 ".($skipUsers?
"INNER JOIN b_user U ON R.USER_ID = U.ID {$skipUserInactiveSql} {$skipUserTypesSql}":
"").
"
229 WHERE R.CHAT_ID = {$chatId} {$whereFields}
230 ORDER BY {$orderField} ASC
233 $relations =
array();
235 while ($row =
$query->fetch())
237 foreach ($row as
$key => $value)
239 if (mb_strpos(
$key,
'USER_DATA_') === 0)
241 $row[
'USER_DATA'][mb_substr(
$key, 10)] = $value;
246 $relations[$row[
'USER_ID']] = $row;
249 $userIds = array_keys($relations);
251 if ((
$params[
'RAW_RELATIONS'] ??
'N') ===
'N')
253 $relations = self::filterRelationsByAccess($chatId, $relations);
258 if (!isset(
$params[
'WITHOUT_COUNTERS']) ||
$params[
'WITHOUT_COUNTERS'] !==
'Y')
262 $counters = $readService->getCounterService()->getByChatForEachUsers($chatId, $userIds);
263 $lastIdInChat = $readService->getLastMessageIdInChat($chatId);
264 $lastReads = $readService->getViewedService()->getDateViewedByMessageIdForEachUser($lastIdInChat, $userIds);
265 foreach ($relations as
$userId => $relation)
286 $chatId = intval($chatId);
296 $relation = self::getRelation($chatId, Array(
297 'SELECT' => Array(
'ID',
'MESSAGE_TYPE',
'NOTIFY_BLOCK',
'COUNTER'),
312 \Bitrix\Im\Model\RelationTable::update($relation[
$userId][
'ID'],
array(
'NOTIFY_BLOCK' =>
$action));
318 if (\
Bitrix\
Main\Loader::includeModule(
'pull'))
320 $element = \Bitrix\Im\Model\RecentTable::getList([
321 'select' => [
'USER_ID',
'ITEM_TYPE',
'ITEM_ID',
'UNREAD'],
324 '=ITEM_TYPE' => $relation[
$userId][
'MESSAGE_TYPE'],
325 '=ITEM_ID' => $chatId
334 'command' =>
'chatMuteNotify',
337 'dialogId' =>
'chat'.$chatId,
341 'lines' => $element[
'ITEM_TYPE'] === self::TYPE_OPEN_LINE,
342 'unread' => ($element[
'UNREAD'] ??
'N') ===
'Y',
343 'counterType' => $chatObject->getCounterType()->value,
344 'recentConfig' => $chatObject->getRecentConfig()->toPullFormat(),
353 'CHAT_ID' => $chatId,
365 $chatId = intval($chatId);
377 $relationData = \Bitrix\Im\Model\RelationTable::getList(Array(
378 'select' => Array(
'START_ID'),
379 'filter' => Array(
'=CHAT_ID' => $chatId,
'=USER_ID' =>
$userId)
382 if (!$relationData || $relationData[
'START_ID'] == 0)
384 $counter = \Bitrix\Im\Model\MessageTable::getCount([
'=CHAT_ID' => $chatId]);
388 $counter = \Bitrix\Im\Model\MessageTable::getCount([
'=CHAT_ID' => $chatId,
'>=ID' => $relationData[
'START_ID']]);
396 $chatId = intval($chatId);
402 return \Bitrix\Im\Dialog::hasAccess(
'chat'.$chatId);
419 $chatData = \Bitrix\Im\Model\ChatTable::getList(Array(
422 'CHAT_TYPE' =>
'TYPE',
423 'CHAT_ENTITY_TYPE' =>
'ENTITY_TYPE',
424 'CHAT_ENTITY_ID' =>
'ENTITY_ID',
425 'RELATION_USER_ID' =>
'RELATION.USER_ID',
426 'RELATION_START_ID' =>
'RELATION.START_ID',
428 'RELATION_LAST_ID' =>
'RELATION.LAST_ID',
432 'filter' => Array(
'=ID' => $chatId),
436 '\Bitrix\Im\Model\RelationTable',
438 "=ref.CHAT_ID" =>
"this.ID",
441 array(
"join_type"=>
"LEFT")
452 $chatData[
'RELATION_UNREAD_ID'] = $readService->getCounterService()->getIdFirstUnreadMessage($chatId) ?? 0;
453 $chatData[
'RELATION_COUNTER'] = $readService->getCounterService()->getByChat($chatId);
454 $chatData[
'RELATION_START_ID'] = (int)$chatData[
'RELATION_START_ID'];
467 '=CHAT_ID' => $chatId
471 $startFromUnread =
false;
476 && $chatData[
'RELATION_COUNTER'] > 0
479 if ($chatData[
'RELATION_COUNTER'] > $limit)
481 $startFromUnread =
true;
482 $options[
'FIRST_ID'] = $chatData[
'RELATION_LAST_ID'];
486 $limit += $chatData[
'RELATION_COUNTER'];
495 if ($chatData[
'RELATION_START_ID'] > 0 && intval(
$options[
'FIRST_ID']) < $chatData[
'RELATION_START_ID'])
497 $filter[
'>=ID'] = $chatData[
'RELATION_START_ID'];
501 if (intval(
$options[
'FIRST_ID']) > 0)
510 $orderId = Array(
'CHAT_ID' =>
'ASC',
'ID' =>
'DESC');
511 $orderResult = Array(
'ID' =>
'DESC');
513 if ($chatData[
'RELATION_START_ID'] > 0)
515 $filter[
'>=ID'] = $chatData[
'RELATION_START_ID'];
524 $orm = \Bitrix\Im\Model\MessageTable::getList(
array(
530 $ids = array_map(fn ($item) => $item[
'ID'], $orm->fetchAll());
534 'CHAT_ID' => (int)$chatId,
546 $orm = \Bitrix\Im\Model\MessageTable::getList(
array(
548 'ID',
'AUTHOR_ID',
'DATE_CREATE',
'NOTIFY_EVENT',
'MESSAGE',
549 'USER_LAST_ACTIVITY_DATE' =>
'AUTHOR.LAST_ACTIVITY_DATE',
553 'MESSAGE_UUID' =>
'UUID.UUID',
555 'filter' => [
'=ID' => $ids],
556 'order' => $orderResult,
561 $userOptions = [
'SKIP_ONLINE' =>
'Y'];
564 $userOptions[
'JSON'] =
'Y';
566 if ($chatData[
'CHAT_ENTITY_TYPE'] ==
'LIVECHAT')
568 [$lineId] = explode(
'|', $chatData[
'CHAT_ENTITY_ID']);
569 $userOptions[
'LIVECHAT'] = $lineId;
570 $userOptions[
'USER_CODE'] =
'livechat|' . $lineId .
'|' . $chatData[
'CHAT_ID'] .
'|' .
$userId;
576 if (
$message[
'NOTIFY_EVENT'] ==
'private_system')
581 if (isset(
$options[
'USER_TAG_SPREAD']) &&
$options[
'USER_TAG_SPREAD'] ===
'Y')
583 $message[
'MESSAGE'] = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", Array(
'\Bitrix\Im\Text',
'modifyShortUserTag'),
$message[
'MESSAGE']);
588 'CHAT_ID' => (
int)$chatId,
589 'AUTHOR_ID' => (
int)
$message[
'AUTHOR_ID'],
592 'UNREAD' => $chatData[
'RELATION_USER_ID'] > 0 && $chatData[
'RELATION_LAST_ID'] <
$message[
'ID'],
599 $user[
'last_activity_date'] =
$message[
'USER_LAST_ACTIVITY_DATE']? date(
'c',
$message[
'USER_LAST_ACTIVITY_DATE']->getTimestamp()):
false;
600 $user[
'desktop_last_date'] =
false;
601 $user[
'mobile_last_date'] =
false;
602 $user[
'idle'] =
false;
621 && !isset($param[
'FILE_ID'])
622 && !isset($param[
'KEYBOARD'])
623 && !isset($param[
'ATTACH'])
630 if (isset($param[
'FILE_ID']))
632 foreach ($param[
'FILE_ID'] as $fileId)
634 $fileIds[$fileId] = $fileId;
638 if (isset($param[
'CHAT_USER']) && is_array($param[
'CHAT_USER']))
640 foreach ($param[
'CHAT_USER'] as $paramsUserId)
642 $users[$paramsUserId] =
User::getInstance($paramsUserId)->getArray($userOptions);
647 $disappearing = DisappearService::getMessagesDisappearingTime(array_keys(
$messages));
668 'CHAT_ID' => (
int)$chatId,
670 'USERS' => array_values($users),
671 'FILES' => array_values(
$files),
679 if ($startFromUnread)
682 $additionalMessages = self::getMessages($chatId,
$userId, [
684 'LAST_ID' => $chatData[
'RELATION_UNREAD_ID']
686 $result[
'MESSAGES'] = array_merge(
$result[
'MESSAGES'], $additionalMessages[
'MESSAGES']);
695 $result[
'MESSAGES'][
$key][
'DATE'] = date(
'c', $value[
'DATE']->getTimestamp());
698 if (isset($value[
'PARAMS'][
'CHAT_LAST_DATE']) && $value[
'PARAMS'][
'CHAT_LAST_DATE'] instanceof \
Bitrix\
Main\
Type\
DateTime)
700 $result[
'MESSAGES'][
$key][
'PARAMS'][
'CHAT_LAST_DATE'] = date(
'c', $value[
'PARAMS'][
'CHAT_LAST_DATE']->getTimestamp());
703 if (is_array($value[
'REPLACES']) && !empty($value[
'REPLACES']))
716 $result[
'FILES'][
$key][
'date'] = date(
'c', $value[
'date']->getTimestamp());
719 foreach ([
'urlPreview',
'urlShow',
'urlDownload'] as $field)
722 if (is_string(
$url) &&
$url && mb_strpos(
$url,
'http') !== 0)
739 'SELECT' => [
'ID',
'USER_ID'],
740 'SKIP_INACTIVE_USER' =>
'Y',
741 'WITHOUT_COUNTERS' =>
'Y',
744 $skipExternal = isset(
$options[
'SKIP_EXTERNAL']) || isset(
$options[
'SKIP_EXTERNAL_EXCEPT_TYPES']);
747 $exceptType =
$options[
'SKIP_EXTERNAL_EXCEPT_TYPES'] ?? [];
766 $relations = self::getRelation($chatId,
$params);
767 foreach ($relations as
$user)
773 if ($userData[
'bot'])
775 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_LOWER | Converter::KEYS);
778 $userData[
'bot_data'] = (!empty($botData)) ? $converter->process($botData) :
null;
782 $userData[
'bot_data'] =
null;
785 $users[] = $userData;
808 $checkAccessParam =
$params[
'CHECK_ACCESS'] ??
null;
809 $chats = self::getList(Array(
810 'FILTER' => Array(
'ID' => $id),
811 'SKIP_ACCESS_CHECK' => $checkAccessParam ===
'Y'?
'N':
'Y',
825 $userOptions = [
'SKIP_ONLINE' =>
'Y'];
826 if ($chat[
'ENTITY_TYPE'] ==
'LIVECHAT')
828 [$lineId] = explode(
'|', $chat[
'CHAT_ENTITY_ID']);
829 $userOptions[
'LIVECHAT'] = $lineId;
830 $userOptions[
'USER_CODE'] =
'livechat|' . $lineId .
'|' . $id .
'|' .
$userId;
833 $relations = self::getRelation($id);
835 $chat[
'READED_LIST'] = [];
836 $chat[
'MANAGER_LIST'] = [];
837 foreach ($relations as $relation)
840 $relation[
'USER_ID'] !=
$userId
846 $chat[
'READED_LIST'][] = [
847 'USER_ID' => (int)$relation[
'USER_ID'],
848 'USER_NAME' =>
$user[
'NAME'],
849 'MESSAGE_ID' => (
int)$relation[
'LAST_ID'],
850 'DATE' => $relation[
'LAST_READ'],
854 if ($relation[
'MANAGER'] ===
'Y')
856 $chat[
'MANAGER_LIST'][] = (int)$relation[
'USER_ID'];
863 $chat[
'LAST_MESSAGE_VIEWS'] = $chatInstance->getLastMessageViews();
870 $chat = self::toJson($chat);
887 $params[
'SKIP_ACCESS_CHECK'] =
$params[
'SKIP_ACCESS_CHECK'] ===
'Y'?
'Y':
'N';
895 $enableLimit =
false;
898 $filterLimit = intval(
$params[
'LIMIT']);
899 $filterLimit = $filterLimit <= 0? self::FILTER_LIMIT: $filterLimit;
901 $filterOffset = intval(
$params[
'OFFSET']);
907 $filterLimit =
false;
908 $filterOffset =
false;
911 $ormParams = self::getListParams(
$params);
918 $ormParams[
'offset'] = $filterOffset;
919 $ormParams[
'limit'] = $filterLimit;
923 $ormParams[
'order'] =
$params[
'ORDER'];
926 $orm = \Bitrix\Im\Model\ChatTable::getList($ormParams);
927 $chatsRaw = $orm->fetchAll();
928 $chatsRaw = self::fillCounterData($chatsRaw);
931 foreach ($chatsRaw as $chatRaw)
933 $chats[] = self::formatChatData($chatRaw);
938 $chats = self::toJson($chats);
946 $generalChatId = \CIMChat::GetGeneralChatId();
947 $avatar = \CIMChat::GetAvatarImage($chat[
'AVATAR'], 200,
false);
950 if ($generalChatId == $chat[
'ID'])
952 $chat[
"ENTITY_TYPE"] =
'GENERAL';
958 if ($chat[
'RELATION_NOTIFY_BLOCK'] ==
'Y')
960 $muteList[] = (int)$chat[
'RELATION_USER_ID'];
963 $counter = (int)$chat[
'RELATION_COUNTER'];
964 $startCounter = (int)$chat[
'RELATION_START_COUNTER'];
965 $userCounter = (int)$chat[
'USER_COUNT'];
966 $unreadId = (int)$chat[
'RELATION_UNREAD_ID'];
967 $lastMessageId = (int)$chat[
'LAST_MESSAGE_ID'];
970 if ($chat[
'ALIAS_NAME'])
973 'code' => $chat[
'ALIAS_NAME'],
978 $options = \CIMChat::GetChatOptions();
979 $restrictions =
$options[
'DEFAULT'];
981 if ($chat[
"ENTITY_TYPE"] && in_array($chat[
"ENTITY_TYPE"], array_keys(
$options),
true))
983 $restrictions =
$options[$chat[
'ENTITY_TYPE']];
987 'ID' => (
int)$chat[
'ID'],
988 'PARENT_CHAT_ID' => (
int)$chat[
'PARENT_ID'],
989 'PARENT_MESSAGE_ID' => (
int)$chat[
'PARENT_MID'],
990 'NAME' => $chat[
'TITLE'],
991 'DESCRIPTION' => $chat[
'DESCRIPTION'],
992 'OWNER' => (
int)$chat[
'AUTHOR_ID'],
993 'EXTRANET' => $chat[
'EXTRANET'] ==
'Y',
998 'USER_COUNTER' => $userCounter,
999 'MESSAGE_COUNT' => (
int)$chat[
'MESSAGE_COUNT'] - $startCounter,
1000 'UNREAD_ID' => $unreadId,
1001 'RESTRICTIONS' => $restrictions,
1002 'LAST_MESSAGE_ID' => $lastMessageId,
1003 'LAST_ID' => (
int)$chat[
'RELATION_LAST_ID'],
1004 'MARKED_ID' => (
int)$chat[
'MARKED_ID'],
1005 'DISK_FOLDER_ID' => (
int)$chat[
'DISK_FOLDER_ID'],
1006 'ENTITY_TYPE' => (
string)$chat[
'ENTITY_TYPE'],
1007 'ENTITY_ID' => (
string)$chat[
'ENTITY_ID'],
1008 'ENTITY_DATA_1' => (
string)$chat[
'ENTITY_DATA_1'],
1009 'ENTITY_DATA_2' => (
string)$chat[
'ENTITY_DATA_2'],
1010 'ENTITY_DATA_3' => (
string)$chat[
'ENTITY_DATA_3'],
1011 'MUTE_LIST' => $muteList,
1012 'DATE_CREATE' => $chat[
'DATE_CREATE'],
1013 'MESSAGE_TYPE' => $chat[
"TYPE"],
1014 'PUBLIC' => $publicOption,
1015 'ROLE' => mb_strtolower(self::getRole($chat)),
1016 'ENTITY_LINK' => EntityLink::getInstance(\CIMChat::initChatByArray($chat))->toArray(),
1018 'BACKGROUND_ID' => (
new Background((
int)$chat[
'ID']))->
get(),
1020 'MANAGE_USERS_ADD' => mb_strtolower((
string)$chat[
'MANAGE_USERS_ADD']),
1021 'MANAGE_USERS_DELETE' => mb_strtolower((
string)$chat[
'MANAGE_USERS_DELETE']),
1022 'MANAGE_UI' => mb_strtolower((
string)$chat[
'MANAGE_UI']),
1023 'MANAGE_SETTINGS' => mb_strtolower((
string)$chat[
'MANAGE_SETTINGS']),
1024 'MANAGE_MESSAGES' => mb_strtolower((
string)$chat[
'CAN_POST']),
1025 'CAN_POST' => mb_strtolower((
string)$chat[
'CAN_POST']),
1027 'IS_NEW' => \CIMChat::isNewChat($chat[
'TYPE'], $chat[
'DATE_CREATE']),
1050 $field =
'*INDEX.SEARCH_CONTENT';
1052 if (isset(
$params[
'FILTER'][
'SEARCH']))
1054 $find = (string)
$params[
'FILTER'][
'SEARCH'];
1056 elseif (isset(
$params[
'FILTER'][
'SEARCH_OL']) && Loader::includeModule(
'imopenlines'))
1058 $find = (string)
$params[
'FILTER'][
'SEARCH_OL'];
1059 $field =
'*OL_INDEX.SEARCH_TITLE';
1062 if (isset(
$params[
'FILTER'][
'ID']))
1066 else if (isset($find))
1068 $helper = Application::getConnection()->getSqlHelper();
1069 if (
Model\ChatIndexTable::getEntity()->fullTextIndexEnabled(
'SEARCH_CONTENT'))
1071 $find = trim($find);
1085 if (mb_strlen($find) < 3)
1090 $filter[
'%=INDEX.SEARCH_TITLE'] = $helper->forSql($find).
'%';
1094 if (
$params[
'SKIP_ACCESS_CHECK'] ===
'Y')
1111 $filter[
'=TYPE'][] = self::TYPE_OPEN_LINE;
1115 '=RELATION.USER_ID' =>
$params[
'CURRENT_USER']
1118 '=RECENT_OL.USER_ID' =>
$params[
'CURRENT_USER']
1132 '=TYPE' => self::TYPE_OPEN,
1135 '=TYPE' => self::TYPE_GROUP,
1136 '=RELATION.USER_ID' =>
$params[
'CURRENT_USER']
1139 '=TYPE' => self::TYPE_THREAD,
1140 '=RELATION.USER_ID' =>
$params[
'CURRENT_USER']
1143 '=TYPE' => self::TYPE_PRIVATE,
1144 '=RELATION.USER_ID' =>
$params[
'CURRENT_USER']
1147 '=TYPE' => self::TYPE_OPEN_LINE,
1148 '=RELATION.USER_ID' =>
$params[
'CURRENT_USER']
1151 if (Loader::includeModule(
'imopenlines'))
1154 '=TYPE' => self::TYPE_OPEN_LINE,
1155 '=RECENT_OL.USER_ID' =>
$params[
'CURRENT_USER']
1161 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1163 'Bitrix\Im\Model\RelationTable',
1165 "=ref.CHAT_ID" =>
"this.ID",
1168 array(
"join_type"=>
"LEFT")
1170 if (Loader::includeModule(
'imopenlines'))
1172 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1176 "=ref.CHAT_ID" =>
"this.ID",
1179 array(
"join_type"=>
"LEFT")
1186 'RELATION_USER_ID' =>
'RELATION.USER_ID',
1187 'RELATION_MANAGER' =>
'RELATION.MANAGER',
1188 'RELATION_NOTIFY_BLOCK' =>
'RELATION.NOTIFY_BLOCK',
1190 'RELATION_START_COUNTER' =>
'RELATION.START_COUNTER',
1191 'RELATION_LAST_ID' =>
'RELATION.LAST_ID',
1194 'ALIAS_NAME' =>
'ALIAS.ALIAS',
1197 'runtime' => $runtime
1203 return \Bitrix\Im\Common::toJson($array,
false);
1218 $result = \Bitrix\Im\Model\RelationTable::getList(
1223 '=CHAT_ID' => $chatId
1243 $result = BlockUserTable::getList(
1248 '=CHAT_ID' => $chatId
1283 $chatOptions = \CIMChat::GetChatOptions();
1284 $isAllowedByDefault = (bool)($chatOptions[
'DEFAULT'][
$action] ??
true);
1286 if ($entityType && $chatOptions[$entityType])
1288 return (
bool)($chatOptions[$entityType][
$action] ?? $isAllowedByDefault);
1293 return $isAllowedByDefault;
1299 return $isAllowedByDefault;
1302 $generalChatId = (int)\CIMChat::GetGeneralChatId();
1303 if ($chatId === $generalChatId)
1305 return (
bool)($chatOptions[
'GENERAL'][
$action] ?? $isAllowedByDefault);
1308 $chat = \Bitrix\Im\Model\ChatTable::getList([
1318 $entityType = ($chat && $chat[
'ENTITY_TYPE']) ? $chat[
'ENTITY_TYPE'] :
null;
1320 if ($entityType && $chatOptions[$entityType])
1322 return (
bool)($chatOptions[$entityType][
$action] ?? $isAllowedByDefault);
1325 return $isAllowedByDefault;
1347 $chat = \Bitrix\Im\Model\ChatTable::getList([
1357 return ($chat && is_numeric($chat[
'AUTHOR_ID'])) ? (int)$chat[
'AUTHOR_ID'] :
null;
1372 foreach ($chats as $chat)
1374 $chatIds[] = (int)$chat[
'ID'];
1377 $counters = $readService->getCounterService()->getForEachChat($chatIds);
1378 $unreadIds = $readService->getCounterService()->getIdFirstUnreadMessageForEachChats($chatIds);
1381 foreach ($chats as
$key => $chat)
1383 $id = (int)$chat[
'ID'];
1385 $chats[
$key][
'RELATION_UNREAD_ID'] = $unreadIds[$id] ?? 0;
1386 $chats[
$key][
'MARKED_ID'] = $markedIds[$id] ?? 0;
1394 $userIds = array_keys($relations);
1396 ->getRelationFacade()
1397 ?->filterUserIdsByAccess($userIds)
1401 return array_filter(
1403 static fn (
$userId) => in_array(
$userId, $usersWithAccess,
true),
1404 ARRAY_FILTER_USE_KEY
1408 private static function getRole(
array $chat): string
1410 if (!isset($chat[
'RELATION_USER_ID']))
1412 return \Bitrix\Im\V2\Chat::ROLE_GUEST;
1414 if ((
int)$chat[
'RELATION_USER_ID'] === (
int)$chat[
'AUTHOR_ID'])
1416 return \Bitrix\Im\V2\Chat::ROLE_OWNER;
1418 if ($chat[
'RELATION_MANAGER'] ===
'Y')
1420 return \Bitrix\Im\V2\Chat::ROLE_MANAGER;
1423 return \Bitrix\Im\V2\Chat::ROLE_MEMBER;
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getPublicLink($type, $alias)
static isUserInChat($chatId, $userId=0)
static fillCounterData(array $chats)
static isGeneralChannel(?int $chatId, string $typeLiteral, string $entityType)
static hasAccess($chatId)
static getMessageCount($chatId, $userId=null)
static getUsers($chatId, $options=[])
static getMessages($chatId, $userId=null, $options=Array())
static getById($id, $params=array())
static getListParams($params)
static getList($params=array())
static formatChatData($chat)
static isActionAllowed($dialogId, $action, $entityType=null)
static getType($chatData, bool $camelCase=true)
static filterRelationsByAccess(int $chatId, array $relations)
static isGeneralChat(?int $chatId, string $typeLiteral, string $entityType)
static isUserKickedFromChat($chatId, $userId=0)
static getOwnerById($dialogId)
static getRelation($chatId, $params=[])
static mute($chatId, $action, $userId=null)
static checkReplicaDeprecatedAgent()
static getColorByNumber($number)
static toJson($array, $camelCase=true)
static getUserId($userId=null)
static getChatId($dialogId, $userId=null)
static filterExternalUserTypes(array $skipTypes=[])
static getMarkedIdByChatIds(int $userId, array $chatIds)
static parse($text, $params=Array())
static parseLegacyFormat($text, $params=Array())
static getReplaceMap($text)
static getInstance($userId=null)
static getGeneralChannelId()
static getGeneralChatId()
static getInstance(?int $id)
static clearCache($moduleId)
static prepareStringToken($token)
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static GetFiles($chatId, $fileId=false, $checkPermission=true)
static prepareShow($arMessages, $params)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
ExecuteModuleEventEx($arEvent, $arParams=[])
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']