7use Bitrix\Im\V2\Analytics\MessageAnalytics;
8use Bitrix\Im\V2\Chat\Background\Background;
9use Bitrix\Im\V2\Chat\TextField\TextFieldEnabled;
10use Bitrix\Im\V2\Chat\Member\Provider\MemberProvider;
11use Bitrix\Im\V2\Entity\User\UserCollection;
12use Bitrix\Im\V2\Entity\User\UserError;
13use Bitrix\Im\V2\Async\Promise\BackgroundJobPromise;
14use Bitrix\Im\V2\Entity\User\UserType;
15use Bitrix\Im\V2\Integration\AI\AIHelper;
17use Bitrix\Im\V2\Integration\Socialnetwork\Group;
18use Bitrix\Im\V2\Message\Counter\CounterType;
19use Bitrix\Im\V2\Message\ReadService;
20use Bitrix\Im\V2\Message\Send\MentionService;
21use Bitrix\Im\V2\Message\Send\PushService;
22use Bitrix\Im\V2\Message\Send\SendingService;
23use Bitrix\Im\V2\Message\Send\SendResult;
24use Bitrix\Im\V2\Permission\Action;
25use Bitrix\Im\V2\Recent\Config\ChatRecentConfig;
26use Bitrix\Im\V2\Recent\Config\RecentConfigManager;
27use Bitrix\Im\V2\Relation\AddUsersConfig;
28use Bitrix\Im\V2\Relation\DeleteUserConfig;
29use Bitrix\Im\V2\Relation\Provider\RelationProvider;
30use Bitrix\Im\V2\Relation\Reason;
31use Bitrix\Im\V2\Relation\RelationChangeSet;
32use Bitrix\Im\V2\Rest\PopupData;
33use Bitrix\Im\V2\Rest\PopupDataAggregatable;
34use Bitrix\Im\V2\Rest\RestEntity;
36use Bitrix\Main\Application;
37use Bitrix\Main\Config\Option;
38use Bitrix\Main\Engine\Response\Converter;
39use Bitrix\Main\Localization\Loc;
40use Bitrix\Main\ORM\Data\DataManager;
41use Bitrix\Main\ORM\Fields\Relations\Reference;
42use Bitrix\Main\ORM\Query\Join;
43use Bitrix\Main\Type\DateTime;
47use Bitrix\Im\Model\ChatTable;
48use Bitrix\Im\Model\EO_Chat;
49use Bitrix\Im\Model\RelationTable;
50use Bitrix\Im\V2\Service\Locator;
51use Bitrix\Im\V2\Service\Context;
52use Bitrix\Im\V2\Chat\ChatFactory;
53use Bitrix\Im\V2\Chat\ChatError;
54use Bitrix\Im\V2\Common\ContextCustomer;
55use Bitrix\Im\V2\Common\ActiveRecordImplementation;
56use Bitrix\Im\V2\Common\RegistryEntryImplementation;
57use Bitrix\Im\V2\Message\MessageError;
58use Bitrix\Im\V2\Message\Send\SendingConfig;
59use Bitrix\Im\V2\Chat\Param\Params;
75 use RegistryEntryImplementation;
76 use ActiveRecordImplementation
98 self::IM_TYPE_PRIVATE,
100 self::IM_TYPE_COMMENT,
101 self::IM_TYPE_OPEN_LINE,
102 self::IM_TYPE_SYSTEM,
103 self::IM_TYPE_CHANNEL,
104 self::IM_TYPE_OPEN_CHANNEL,
106 self::IM_TYPE_COPILOT,
107 self::IM_TYPE_COLLAB,
108 self::IM_TYPE_EXTERNAL,
109 self::IM_TYPE_AI_ASSISTANT,
110 self::IM_TYPE_AI_ASSISTANT_ENTITY,
114 'PRIVATE' => self::IM_TYPE_PRIVATE,
115 'CHAT' => self::IM_TYPE_CHAT,
116 'COMMENT' => self::IM_TYPE_COMMENT,
117 'OPENLINE' => self::IM_TYPE_OPEN_LINE,
118 'SYSTEM' => self::IM_TYPE_SYSTEM,
119 'NOTIFY' => self::IM_TYPE_SYSTEM,
120 'CHANNEL' => self::IM_TYPE_CHANNEL,
121 'OPEN_CHANNEL' => self::IM_TYPE_OPEN_CHANNEL,
122 'OPEN' => self::IM_TYPE_OPEN,
123 'COPILOT' => self::IM_TYPE_COPILOT,
124 'COLLAB' => self::IM_TYPE_COLLAB,
125 'EXTERNAL' => self::IM_TYPE_EXTERNAL
143 self::ENTITY_TYPE_LINE,
144 self::ENTITY_TYPE_LIVECHAT,
145 self::ENTITY_TYPE_FAVORITE,
146 self::ENTITY_TYPE_VIDEOCONF,
167 'messagesAutoDeleteDelay',
170 'conferencePassword',
187 private const CHUNK_SIZE = 1000;
314 $this->initByDefault();
318 $this->
load($source);
321 $this->messageRegistry =
new Registry;
322 $this->recentConfigManager = RecentConfigManager::getInstance();
342 if (isset(self::$chatStaticCache[
$chatId]))
344 return self::$chatStaticCache[
$chatId];
354 self::$chatStaticCache[
$chatId] = $chat;
356 return self::$chatStaticCache[
$chatId];
359 public static function cleanCache(
int $id,
bool $cleanStaticCache =
true): void
361 if ($cleanStaticCache)
363 unset(self::$chatStaticCache[$id]);
367 Im\V2\Chat\EntityLink::cleanCache($id);
372 if (isset(self::$chatStaticCache[
$chatId]))
374 self::$chatStaticCache[
$chatId]->accessCache = [];
381 $result = $this->defaultSave();
388 if ($id !==
null && (
$result->getResult()[
'IS_CHANGES'] ??
true) ===
true)
390 self::cleanCache($id);
412 return isset($this->chatId);
427 return $this->recentConfigManager->getRecentSectionsByChat($this);
442 return (
bool)$this->
getChatParams()->get(Params::CONTAINS_COLLABER)?->getValue();
459 return $this->usersIds;
464 return $this->aliasName;
476 if (is_string($alias))
486 return $alias[
'ALIAS'] ??
null;
491 if (!isset($this->markedId))
496 return $this->markedId;
516 if (isset($this->role))
523 if ($selfRelation ===
null)
525 $this->role = self::ROLE_GUEST;
532 $this->role = self::ROLE_OWNER;
537 elseif ($selfRelation->getManager())
539 $this->role = self::ROLE_MANAGER;
543 $this->role = self::ROLE_MEMBER;
553 CGlobalCounter::Increment(
'im_chat_color_id', CGlobalCounter::ALL_SITES,
false);
554 $chatColorId = CGlobalCounter::GetValue(
'im_chat_color_id', CGlobalCounter::ALL_SITES);
570 $this->chatParams ??= $this->
getId() !==
null
571 ? Params::getInstance($this->
getId())
572 : Params::loadWithoutChat([])
575 return $this->chatParams;
584 if (isset($this->accessCache[
$userId]))
586 return $this->accessCache[
$userId];
593 return $this->accessCache[
$userId];
598 return $this->accessCache[
$userId];
611 $userId = $this->getContext()->getUserId();
635 return $this->messageRegistry;
644 if (isset($this->messageRegistry[
$messageId]))
650 $message->setRegistry($this->messageRegistry);
653 if ($loadResult->isSuccess())
670 if (!$onBeforeResult->isSuccess())
672 return $result->addErrors($onBeforeResult->getErrors());
675 $checkUuidResult = $sendService->checkDuplicateByUuid(
$message);
676 if (!$checkUuidResult->isSuccess())
678 return $result->addErrors($checkUuidResult->getErrors());
681 $data = $checkUuidResult->getResult();
682 if (!empty(
$data[
'messageId']))
687 $message->autocompleteParams($sendingConfig);
689 $eventResult = $sendService->fireEventBeforeSend($this,
$message);
690 if (!$eventResult->isSuccess())
692 return $result->addErrors($eventResult->getErrors());
695 if (
$message->getChatId() !== $this->getId())
708 if (!$saveResult->isSuccess())
710 return $result->addErrors($saveResult->getErrors());
727 && !$this->getContext()->getUser()->isBot()
728 && !
$message->getChat()->getTextFieldEnabled()->get()
744 $authorContext =
$message->getContext();
745 $sendingConfig = $sendingService->
getConfig();
750 if ($sendingConfig->convertMode())
756 $counters = $updateStateResult->getResult()[
'COUNTERS'] ?? [];
767 $newConfig->skipFireEventBeforeMessageNotifySend();
775 ->setRegistry($this->messageRegistry)
776 ->setContextUser(
$message->getAuthorId() ?: $this->getContext()->getUserId())
777 ->setChatId($this->
getId())
779 ->filterMessageText()
789 if (!$sendingConfig->addRecent())
803 \Bitrix\Im\Model\ChatTable::update($this->
getId(), [
805 'LAST_MESSAGE_ID' =>
$message->getId(),
807 $this->messageCount = $countMessageBeforeUpdate + 1;
808 $this->lastMessageId =
$message->getId();
823 if (
$config->skipAuthorAddRecent())
825 unset($usersToAddToRecent[
$message->getAuthorId()]);
840 Im\Model\RecentTable::updateByFilter(
841 [
'=ITEM_CID' => $this->
getId()],
871 Im\Model\RecentTable::multiplyInsertWithoutDuplicate(
873 [
'DEADLOCK_SAFE' =>
true,
'UNIQUE_FIELDS' => [
'USER_ID',
'ITEM_TYPE',
'ITEM_ID']]
881 if ($relationId ===
null)
888 'ITEM_TYPE' => $this->
getType(),
889 'ITEM_ID' => $this->
getId(),
891 'ITEM_CID' => $this->
getId(),
892 'ITEM_RID' => $relationId,
893 'DATE_MESSAGE' =>
$message->getDateCreate(),
894 'DATE_LAST_ACTIVITY' =>
$message->getDateCreate(),
895 'DATE_UPDATE' =>
$message->getDateCreate(),
903 'DATE_MESSAGE' =>
$message->getDateCreate(),
904 'DATE_UPDATE' =>
$message->getDateCreate(),
905 'DATE_LAST_ACTIVITY' =>
$message->getDateCreate(),
912 ->getByUserId(
$message->getActionContextUserId(), $this->getId())
914 ?->setLastSendMessageId(
$message->getId())
927 ->withContextUser(
$message->getContext()->getUserId())
941 $this->getRelations()->getUserIds(),
964 $message->setRegistry($this->messageRegistry);
994 foreach ($chats as $chat)
996 $chatIds[] = $chat->getId();
1004 $relationEntities = RelationTable::query()
1007 ->whereIn(
'CHAT_ID', $chatIds)
1012 foreach ($chats as $chat)
1014 $chat->getRelationFacade()?->preloadUserRelation(
$userId, $relations->getByUserId(
$userId, $chat->getId()));
1030 if (
Main\Loader::includeModule(
'pull'))
1033 'module_id' =>
'im',
1034 'command' =>
'readAllChats',
1042 public function read(
bool $onlyRecent =
false,
bool $byEvent =
false):
Result
1050 return (
new Result())->setResult([
1051 'CHAT_ID' => $this->chatId,
1053 'COUNTER' => $this->
getReadService()->getCounterService()->getByChat($this->chatId),
1054 'VIEWED_MESSAGES' => [],
1081 $startId =
$readService->getLastIdByChatId($this->chatId);
1083 $counter = $readResult->getResult()[
'COUNTER'] ?? 0;
1084 $viewedMessages = $readResult->getResult()[
'VIEWED_MESSAGES'] ??
new MessageCollection();
1088 $notOwnMessages = $viewedMessages->filter(fn (
Message $message) =>
$message->getAuthorId() !== $this->getContext()->getUserId());
1090 if (
Main\Loader::includeModule(
'pull'))
1092 CIMNotify::DeleteBySubTag(
"IM_MESS_{$this->getChatId()}_{$this->getContext()->getUserId()}",
false,
false);
1093 CPushManager::DeleteFromQueueBySubTag($this->getContext()->
getUserId(),
'IM_MESS');
1100 'CHAT_ID' => $this->chatId,
1103 'VIEWED_MESSAGES' => $notOwnMessages->getIds(),
1110 $startId =
$message->getMessageId();
1112 $counter = $readResult->getResult()[
'COUNTER'] ?? 0;
1114 $viewedMessages = $readResult->getResult()[
'VIEWED_MESSAGES'];
1118 $viewedMessage =
new Message();
1119 $viewedMessage->setMessageId((
int)
$messageId);
1120 $messageCollection->add($viewedMessage);
1125 if (
Main\Loader::includeModule(
'pull'))
1127 CIMNotify::DeleteBySubTag(
"IM_MESS_{$this->getChatId()}_{$this->getContext()->getUserId()}",
false,
false);
1128 CPushManager::DeleteFromQueueBySubTag($this->getContext()->
getUserId(),
'IM_MESS');
1136 'CHAT_ID' => $this->chatId,
1139 'VIEWED_MESSAGES' => $viewedMessages,
1150 if ($this->
getType() === self::ENTITY_TYPE_LIVECHAT || !$this->getContext()->getUser()->isConnector())
1159 if (!
Main\Loader::includeModule(
'pull'))
1165 if ($this->
getType() === self::IM_TYPE_COMMENT)
1167 \CPullWatch::AddToStack(
'IM_PUBLIC_COMMENT_'.$this->
getParentChatId(), $push);
1175 \CPullWatch::AddToStack(
'IM_PUBLIC_'.$this->
getId(), $push);
1177 if ($this->
getType() === self::IM_TYPE_OPEN_CHANNEL)
1189 $muted = isset($selfRelation) ? $selfRelation->getNotifyBlock() :
false;
1191 'module_id' =>
'im',
1192 'command' =>
'readMessageChat',
1200 'muted' => $muted ??
false,
1203 'viewedMessages' =>
$messages->getIds(),
1204 'counterType' => $this->getCounterType()->value,
1205 'recentConfig' => $this->getRecentConfig()->toPullFormat(),
1213 $viewedMessageIds =
$messages->getIds();
1215 'module_id' =>
'im',
1216 'command' =>
'readMessageChatOpponent',
1220 'chatId' => $this->chatId,
1221 'userId' => $this->getContext()->getUserId(),
1222 'userName' => $this->getContext()->getUser()->getName(),
1224 'date' => (
new DateTime())->format(
'c'),
1225 'viewedMessages' => $viewedMessageIds,
1226 'chatMessageStatus' => $this->
getReadService()->getChatMessageStatus($this->chatId),
1230 if ($this->
getType() === Chat::IM_TYPE_COMMENT)
1232 \CPullWatch::AddToStack(
'IM_PUBLIC_COMMENT_' . $this->
getParentChatId(), $pushMessage);
1239 $maxViewedMessageId = !empty($viewedMessageIds) ? max($viewedMessageIds) : 0;
1243 \CPullWatch::AddToStack(
"IM_PUBLIC_{$this->chatId}", $pushMessage);
1250 return $pushMessage;
1258 'CHAT_ID' => $this->chatId,
1261 'START_ID' => $startId,
1264 'USER_ID' => $this->getContext()->
getUserId(),
1265 'BY_EVENT' => $byEvent
1274 if (isset($lastMessageViewsByGroups[
'USERS'][$this->getContext()->
getUserId()]))
1276 return $lastMessageViewsByGroups[
'FOR_VIEWERS'];
1279 return $lastMessageViewsByGroups[
'FOR_NOT_VIEWERS'];
1284 $defaultViewInfo = [
1286 'FIRST_VIEWERS' => [],
1287 'COUNT_OF_VIEWERS' => 0,
1291 'FOR_VIEWERS' => $defaultViewInfo,
1292 'FOR_NOT_VIEWERS' => $defaultViewInfo,
1299 if ($lastMessageInChat === 0)
1304 $messageViewers =
$readService->getViewedService()->getMessageViewersIds($lastMessageInChat);
1305 $countOfView =
count($messageViewers);
1309 foreach ($messageViewers as $messageViewer)
1311 if (
count($firstViewers) >= 2)
1316 $firstViewers[$messageViewer] = $messageViewer;
1319 $datesOfViews =
$readService->getViewedService()->getDateViewedByMessageIdForEachUser($lastMessageInChat, $firstViewers);
1321 $firstViewersWithDate = [];
1323 foreach ($firstViewers as $viewer)
1325 $firstViewersWithDate[] = [
1326 'USER_ID' => $viewer,
1328 'DATE' => $datesOfViews[$viewer] ?? null
1332 $viewsInfoByGroups = [
'USERS' => $messageViewers];
1333 $viewInfoForViewers = [
1334 'MESSAGE_ID' => $lastMessageInChat,
1335 'FIRST_VIEWERS' => $firstViewersWithDate,
1336 'COUNT_OF_VIEWERS' => $countOfView - 1,
1338 $viewInfoForNotViewers = $viewInfoForViewers;
1339 ++$viewInfoForNotViewers[
'COUNT_OF_VIEWERS'];
1340 $viewsInfoByGroups[
'FOR_VIEWERS'] = $viewInfoForViewers;
1341 $viewsInfoByGroups[
'FOR_NOT_VIEWERS'] = $viewInfoForNotViewers;
1343 return $viewsInfoByGroups;
1348 $userId = $this->getContext()->getUserId();
1349 $isLineChat = $this->
getEntityType() === self::ENTITY_TYPE_LINE;
1352 foreach ($relations as $relation)
1354 if ($skipSelf && $relation->getUserId() ===
$userId)
1358 if ($skipBot && $relation->getUser()->isBot())
1362 if ($isLineChat && $relation->getUser()->isConnector())
1366 $userIds[] = $relation->getUserId();
1384 'field' =>
'chatId',
1385 'set' =>
'setChatId',
1386 'get' =>
'getChatId',
1395 'default' =>
'getDefaultType',
1396 'beforeSave' =>
'beforeSaveType',
1399 'field' =>
'authorId',
1400 'set' =>
'setAuthorId',
1401 'get' =>
'getAuthorId',
1403 'CHAT_AUTHOR_ID' => [
1404 'alias' =>
'AUTHOR_ID',
1408 'get' =>
'getColor',
1409 'set' =>
'setColor',
1410 'beforeSave' =>
'checkColor',
1416 'set' =>
'setTitle',
1417 'get' =>
'getTitle',
1418 'beforeSave' =>
'checkTitle',
1422 'field' =>
'description',
1423 'get' =>
'getDescription',
1424 'set' =>
'setDescription',
1428 'field' =>
'parentChatId',
1429 'get' =>
'getParentId',
1430 'set' =>
'setParentId',
1433 'field' =>
'parentMessageId',
1434 'get' =>
'getParentMessageId',
1435 'set' =>
'setParentMessageId',
1438 'field' =>
'extranet',
1439 'get' =>
'getExtranet',
1440 'set' =>
'setExtranet',
1441 'default' =>
'getDefaultExtranet',
1444 'field' =>
'avatarId',
1445 'get' =>
'getAvatarId',
1446 'set' =>
'setAvatarId',
1448 'PIN_MESSAGE_ID' => [
1449 'field' =>
'pinMessageId',
1450 'get' =>
'getPinMessageId',
1451 'set' =>
'setPinMessageId',
1454 'field' =>
'callType',
1455 'get' =>
'getCallType',
1456 'set' =>
'setCallType',
1459 'field' =>
'callNumber',
1460 'get' =>
'getCallNumber',
1461 'set' =>
'setCallNumber',
1464 'field' =>
'entityType',
1465 'get' =>
'getEntityType',
1466 'set' =>
'setEntityType',
1467 'default' =>
'getDefaultEntityType',
1470 'field' =>
'entityId',
1471 'get' =>
'getEntityId',
1472 'set' =>
'setEntityId',
1474 'ENTITY_DATA_1' => [
1475 'field' =>
'entityData1',
1476 'get' =>
'getEntityData1',
1477 'set' =>
'setEntityData1',
1479 'ENTITY_DATA_2' => [
1480 'field' =>
'entityData2',
1481 'get' =>
'getEntityData2',
1482 'set' =>
'setEntityData2',
1484 'ENTITY_DATA_3' => [
1485 'field' =>
'entityData3',
1486 'get' =>
'getEntityData3',
1487 'set' =>
'setEntityData3',
1489 'DISK_FOLDER_ID' => [
1490 'field' =>
'diskFolderId',
1491 'get' =>
'getDiskFolderId',
1492 'set' =>
'setDiskFolderId',
1494 'MESSAGE_COUNT' => [
1495 'field' =>
'messageCount',
1496 'get' =>
'getMessageCount',
1497 'set' =>
'setMessageCount',
1500 'field' =>
'userCount',
1501 'get' =>
'getUserCount',
1502 'set' =>
'setUserCount',
1504 'PREV_MESSAGE_ID' => [
1505 'field' =>
'prevMessageId',
1506 'get' =>
'getPrevMessageId',
1507 'set' =>
'setPrevMessageId',
1509 'LAST_MESSAGE_ID' => [
1510 'field' =>
'lastMessageId',
1511 'get' =>
'getLastMessageId',
1512 'set' =>
'setLastMessageId',
1514 'LAST_MESSAGE_STATUS' => [
1515 'field' =>
'lastMessageStatus',
1516 'get' =>
'getLastMessageStatus',
1517 'set' =>
'setLastMessageStatus',
1518 'default' =>
'getDefaultLastMessageStatus',
1521 'field' =>
'dateCreate',
1522 'get' =>
'getDateCreate',
1523 'set' =>
'setDateCreate',
1524 'default' =>
'getDefaultDateCreate',
1526 'MANAGE_USERS_ADD' => [
1527 'field' =>
'manageUsersAdd',
1528 'get' =>
'getManageUsersAdd',
1529 'set' =>
'setManageUsersAdd',
1530 'default' =>
'getDefaultManageUsersAdd',
1532 'MANAGE_USERS_DELETE' => [
1533 'field' =>
'manageUsersDelete',
1534 'get' =>
'getManageUsersDelete',
1535 'set' =>
'setManageUsersDelete',
1536 'default' =>
'getDefaultManageUsersDelete',
1539 'field' =>
'manageUI',
1540 'get' =>
'getManageUI',
1541 'set' =>
'setManageUI',
1542 'default' =>
'getDefaultManageUI',
1544 'MANAGE_SETTINGS' => [
1545 'field' =>
'manageSettings',
1546 'get' =>
'getManageSettings',
1547 'set' =>
'setManageSettings',
1548 'default' =>
'getDefaultManageSettings',
1550 'MANAGE_MESSAGES_AUTO_DELETE' => [
1551 'get' =>
'getManageMessagesAutoDelete',
1552 'set' =>
'setManageMessagesAutoDelete',
1553 'default' =>
'getDefaultManageMessagesAutoDelete',
1556 'DISAPPEARING_TIME' => [
1557 'field' =>
'messagesAutoDeleteDelay',
1558 'get' =>
'getMessagesAutoDeleteDelay',
1559 'set' =>
'setMessagesAutoDeleteDelay',
1560 'default' =>
'getDefaultMessagesAutoDeleteDelay',
1562 'MESSAGES_AUTO_DELETE_DELAY' => [
1563 'alias' =>
'DISAPPEARING_TIME',
1566 'field' =>
'manageMessages',
1567 'get' =>
'getManageMessages',
1568 'set' =>
'setManageMessages',
1569 'default' =>
'getDefaultManageMessages',
1571 'MANAGE_MESSAGES' => [
1572 'alias' =>
'CAN_POST'
1575 'get' =>
'getUserIds',
1576 'set' =>
'setUserIds',
1579 'field' =>
'aliasName',
1580 'get' =>
'getAliasName',
1581 'set' =>
'setAliasName',
1582 'loadFilter' =>
'prepareAliasToLoad',
1586 'set' =>
'setRelations',
1590 'set' =>
'setChatParams',
1601 return ChatTable::class;
1650 C.PARENT_ID as CHAT_PARENT_ID,
1651 C.PARENT_MID as CHAT_PARENT_MID,
1652 C.TITLE as CHAT_TITLE,
1653 C.AUTHOR_ID as CHAT_AUTHOR_ID,
1654 C.TYPE as CHAT_TYPE,
1655 C.AVATAR as CHAT_AVATAR,
1656 C.COLOR as CHAT_COLOR,
1657 C.ENTITY_TYPE as CHAT_ENTITY_TYPE,
1658 C.ENTITY_ID as CHAT_ENTITY_ID,
1659 C.ENTITY_DATA_1 as CHAT_ENTITY_DATA_1,
1660 C.ENTITY_DATA_2 as CHAT_ENTITY_DATA_2,
1661 C.ENTITY_DATA_3 as CHAT_ENTITY_DATA_3,
1662 C.EXTRANET as CHAT_EXTRANET,
1663 C.PREV_MESSAGE_ID as CHAT_PREV_MESSAGE_ID,
1667 WHERE C.ID = ".(
int)
$params[
'CHAT_ID'].
"
1672 if (empty(
$params[
'FROM_USER_ID']))
1678 if (
$params[
'FROM_USER_ID'] <= 0)
1686 C.PARENT_ID as CHAT_PARENT_ID,
1687 C.PARENT_MID as CHAT_PARENT_MID,
1688 C.TITLE as CHAT_TITLE,
1689 C.AUTHOR_ID as CHAT_AUTHOR_ID,
1690 C.TYPE as CHAT_TYPE,
1691 C.AVATAR as CHAT_AVATAR,
1692 C.COLOR as CHAT_COLOR,
1693 C.ENTITY_TYPE as CHAT_ENTITY_TYPE,
1694 C.ENTITY_ID as CHAT_ENTITY_ID,
1695 C.ENTITY_DATA_1 as CHAT_ENTITY_DATA_1,
1696 C.ENTITY_DATA_2 as CHAT_ENTITY_DATA_2,
1697 C.ENTITY_DATA_3 as CHAT_ENTITY_DATA_3,
1698 C.EXTRANET as CHAT_EXTRANET,
1699 C.PREV_MESSAGE_ID as CHAT_PREV_MESSAGE_ID,
1701 R.MANAGER as IS_MANAGER
1703 LEFT JOIN b_im_relation R
1705 AND R.USER_ID = ".
$params[
'FROM_USER_ID'].
"
1706 WHERE C.ID = ".(
int)
$params[
'CHAT_ID'].
"
1710 if ($row =
$res->fetch())
1713 'ID' => (
int)$row[
'CHAT_ID'],
1714 'TYPE' => $row[
'CHAT_TYPE'],
1715 'ENTITY_TYPE' => $row[
'CHAT_ENTITY_TYPE'],
1716 'ENTITY_ID' => $row[
'CHAT_ENTITY_ID'],
1745 self::IM_TYPE_CHANNEL,
1746 self::IM_TYPE_OPEN_CHANNEL,
1747 self::IM_TYPE_COLLAB,
1750 $recentCollection = Im\Model\RecentTable::query()
1751 ->setSelect([
'ITEM_ID',
'DATE_MESSAGE'])
1752 ->registerRuntimeField(
1755 RelationTable::class,
1756 Join::on(
'this.ITEM_ID',
'ref.CHAT_ID')
1757 ->where(
'this.USER_ID', $currentUserId)
1758 ->where(
'ref.USER_ID',
$userId)
1759 ->whereIn(
'this.ITEM_TYPE', $types),
1760 [
'join_type' => Join::TYPE_INNER]
1763 ->setOrder([
'DATE_MESSAGE' =>
'DESC'])
1765 ->setOffset($offset)
1769 foreach ($recentCollection as $recentItem)
1771 $chat = self::getInstance($recentItem->getItemId());
1776 $chat->dateMessage = $recentItem->getDateMessage();
1777 $chats[$chat->getId()] = $chat;
1799 return $this->chatId;
1820 $this->
setType(self::IM_TYPE_CHAT);
1827 $this->
setType(self::IM_TYPE_PRIVATE);
1850 && $relation->getNotifyBlock()
1869 if ($relation !==
null)
1880 if ($this->dialogId || !$this->
getChatId())
1882 return $this->dialogId;
1885 $this->dialogId =
'chat'. $this->
getChatId();
1887 return $this->dialogId;
1903 $userId ??= Locator::getContext()->getUserId();
1905 [$dialogContextId] = explode(
'/', $contextId);
1906 if (str_starts_with($dialogContextId,
'chat'))
1908 return $dialogContextId;
1911 $userIds = explode(
':', $dialogContextId);
1913 foreach ($userIds as $contextUserId)
1915 if ((
int)$contextUserId !==
$userId)
1917 return $contextUserId;
1930 if (!in_array(
$type, self::IM_TYPES))
1932 if (in_array(
$type, array_keys(self::IM_TYPES_TRANSLATE),
true))
1942 $this->type =
$type;
1960 return CounterType::tryFromChat($this);
1967 if (!in_array($this->type, self::IM_TYPES,
true))
1984 return $this->authorId;
2028 public function getColor(
bool $forRest =
false): ?string
2036 return $this->color;
2065 return $this->parentChatId;
2077 return $this->parentMessageId;
2089 return $this->extranet;
2106 return $this->avatarId;
2109 public function getAvatar(
bool $addBlankPicture =
false,
bool $withDomain =
false): string
2123 return $this->pinMessageId;
2135 return $this->callType;
2147 return $this->callNumber;
2159 if ($this->entityType)
2161 return $this->entityType;
2193 return $this->entityData1;
2205 return $this->entityData2;
2217 return $this->entityData3;
2229 return $this->diskFolderId;
2234 $this->isDiskFolderFilled =
true;
2235 $this->diskFolder = $folder;
2242 if ($folder ===
null)
2253 return (
int)Option::get(
'im',
'disk_storage_id', 0);
2258 if (!
Main\Loader::includeModule(
'disk'))
2263 if ($this->isDiskFolderFilled)
2265 return $this->diskFolder;
2274 if (!($folder instanceof Folder) || (
int)$folder->getStorageId() !== \
CIMDisk::GetStorageId($this->chatId))
2294 $folderModel =
$storage->addFolder(
2296 'NAME' =>
"chat{$this->getId()}",
2297 'CREATED_BY' => $this->getContext()->
getUserId(),
2306 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
2307 $accessProvider->updateChatCodesByRelations($this->
getId());
2310 return $folderModel;
2315 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
2316 $driver = \Bitrix\Disk\Driver::getInstance();
2317 $rightsManager = $driver->getRightsManager();
2321 'ACCESS_CODE' => $accessProvider->generateAccessCode($this->
getId()),
2322 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_EDIT)
2325 return $accessCodes;
2339 return $this->messageCount ?? 0;
2353 return $this->userCount;
2364 if ($this->userCounter ===
null)
2369 return $this->userCounter;
2381 return $this->prevMessageId;
2395 return $this->lastMessageId;
2402 return $this->lastFileId;
2414 return $this->lastMessageStatus;
2419 return \IM_MESSAGE_STATUS_RECEIVED;
2431 return $this->dateCreate;
2441 if ($this->readService ===
null)
2444 $this->readService->setContext($this->context);
2447 return $this->readService;
2471 return $this->chatRelations;
2505 return $this->relationProvider;
2519 return $this->textFieldEnabled;
2526 foreach ($relations as $relation)
2528 if ($relation->getUser()->getExternalAuthId() ===
Im\Bot::EXTERNAL_AUTH_ID)
2530 $botInChat[$relation->getUserId()] = $relation->getUserId();
2556 [self::MANAGE_RIGHTS_MEMBER, self::MANAGE_RIGHTS_OWNER, self::MANAGE_RIGHTS_MANAGERS],
2569 return $this->manageUsersAdd;
2575 return self::MANAGE_RIGHTS_MEMBER;
2587 [self::MANAGE_RIGHTS_MEMBER, self::MANAGE_RIGHTS_OWNER, self::MANAGE_RIGHTS_MANAGERS],
2600 return $this->manageUsersDelete;
2606 return self::MANAGE_RIGHTS_MANAGERS;
2618 [self::MANAGE_RIGHTS_MEMBER, self::MANAGE_RIGHTS_OWNER, self::MANAGE_RIGHTS_MANAGERS],
2631 return $this->manageUI;
2636 return self::MANAGE_RIGHTS_MEMBER;
2646 if (!in_array(
$manageSettings, [self::MANAGE_RIGHTS_OWNER, self::MANAGE_RIGHTS_MANAGERS],
true))
2657 return $this->manageSettings;
2662 return self::MANAGE_RIGHTS_OWNER;
2707 self::MANAGE_RIGHTS_NONE,
2708 self::MANAGE_RIGHTS_MEMBER,
2709 self::MANAGE_RIGHTS_OWNER,
2710 self::MANAGE_RIGHTS_MANAGERS
2724 return $this->manageMessages;
2729 return self::MANAGE_RIGHTS_MEMBER;
2734 $manageMessagesAutoDelete = mb_strtoupper($manageMessagesAutoDelete);
2737 $manageMessagesAutoDelete,
2739 self::MANAGE_RIGHTS_NONE,
2740 self::MANAGE_RIGHTS_MEMBER,
2741 self::MANAGE_RIGHTS_OWNER,
2742 self::MANAGE_RIGHTS_MANAGERS,
2755 Params::MANAGE_MESSAGES_AUTO_DELETE,
2765 Params::MANAGE_MESSAGES_AUTO_DELETE,
2766 $manageMessagesAutoDelete,
2777 $manageMessagesAutoDelete = $this->
getChatParams()?->get(Params::MANAGE_MESSAGES_AUTO_DELETE);
2780 isset($manageMessagesAutoDelete)
2781 ? (string)$manageMessagesAutoDelete->getValue()
2788 return self::MANAGE_RIGHTS_MANAGERS;
2794 self::MANAGE_RIGHTS_NONE => Loc::getMessage(
'IM_CHAT_CAN_POST_NONE'),
2795 self::MANAGE_RIGHTS_MEMBER => Loc::getMessage(
'IM_CHAT_CAN_POST_ALL_MSGVER_1'),
2796 self::MANAGE_RIGHTS_OWNER => Loc::getMessage(
'IM_CHAT_CAN_POST_OWNER_MSGVER_1'),
2797 self::MANAGE_RIGHTS_MANAGERS => Loc::getMessage(
'IM_CHAT_CAN_POST_MANAGERS_MSGVER_1')
2803 if (!isset($this->callToken))
2808 return $this->callToken;
2819 $userId ??= $this->getContext()->getUserId();
2824 public function join(
bool $withMessage =
true): self
2837 if (empty($userIds) || !$this->
getChatId())
2845 if ($changes->isEmpty())
2872 if (empty($userIds))
2881 $relation = $usersAlreadyInChat->getByUserId(
$userId, $this->
getId() ?? 0);
2891 $changes->addNewMembers(
$userId);
2892 $relation->markAsHidden(
false);
2894 if (
$config->reason !== Reason::DEFAULT)
2896 $relation->setReason(
$config->reason);
2900 $usersAlreadyInChat->save(
true);
2907 if (empty($usersToAdd))
2912 $currentUserId = $this->getContext()->getUserId();
2914 foreach ($usersToAdd as
$userId)
2916 $userCodes[] =
"[USER={$userId}][/USER]";
2918 $userCodesString = implode(
', ', $userCodes);
2920 $addsOnlyHimself =
count($usersToAdd) === 1 && (isset($usersToAdd[$currentUserId]) || $currentUserId === 0);
2921 if ($addsOnlyHimself)
2923 $userIdToAdd = current($usersToAdd);
2925 $messageText = Loc::getMessage(
"IM_CHAT_SELF_JOIN_{$userToAdd->getGender()}", [
'#USER_NAME#' => $userCodesString]);
2927 elseif ($currentUserId === 0 &&
count($usersToAdd) > 1)
2929 $messageText = Loc::getMessage(
'IM_CHAT_SELF_JOIN', [
'#USERS_NAME#' => $userCodesString]);
2935 $code =
"IM_{$type}_JOIN_{$currentUser->getGender()}";
2936 $messageText = Loc::getMessage(
2939 '#USER_1_NAME#' =>
"[USER={$currentUserId}][/USER]",
2940 '#USER_2_NAME#' => $userCodesString
2946 "CODE" =>
'CHAT_JOIN',
2947 "NOTIFY" => $this->
getEntityType() === self::ENTITY_TYPE_LINE?
'Y':
'N',
2952 $params[
'FAKE_RELATION'] = (int)array_shift($usersToAdd);
2955 \CIMChat::AddMessage([
2956 'TO_CHAT_ID' => $this->
getId(),
2957 'MESSAGE' => $messageText,
2958 'FROM_USER_ID' => $currentUserId,
2960 'RECENT_ADD' =>
$config->skipRecent ?
'N' :
'Y',
2963 'SKIP_USER_CHECK' =>
'Y',
2964 'SKIP_COUNTER_INCREMENTS' => $this->getEntityType() === self::ENTITY_TYPE_LINE ?
'N' :
'Y',
2970 if (empty($usersToAdd) || !\
Bitrix\
Main\Loader::includeModule(
'pull'))
2980 if (empty($usersToAdd))
2985 foreach ($usersToAdd as
$userId)
2991 self::cleanAccessCache($this->
getId());
2998 if (empty($newMembers))
3003 if (!$this->
getExtranet() && UserCollection::hasUserByType($newMembers, UserType::EXTRANET))
3007 if (!$this->
containsCollaber() && UserCollection::hasUserByType($newMembers, UserType::COLLABER))
3009 $this->
getChatParams()->addParamByName(Params::CONTAINS_COLLABER,
true);
3011 if (!$this->
containsCopilot() && AIHelper::containsCopilotBot($newMembers))
3025 $usersToAdd = array_filter($usersToAdd);
3027 if (empty($usersToAdd))
3033 foreach ($usersToAdd as
$userId)
3036 $relations->add($relation);
3038 $relations->save(
true);
3043 foreach ($usersToAdd as
$userId)
3045 $chatAnalytics->addAddUser();
3051 $hideHistory =
$config->hideHistory ??
false;
3056 ->setChatId($this->
getId())
3057 ->setMessageType($this->
getType())
3063 ->fillRestriction($hideHistory, $this)
3067 $relation->setManager(
true);
3075 $userIds = Group::filterAddedUsersToChatBySonetRestriction($userIds, $this->getContext()->
getUserId());
3077 if ($this->getContext()->getUser()->isExtranet())
3105 return $user->isExist() &&
$user->isActive();
3110 if (empty($usersToAdd))
3115 foreach ($usersToAdd as
$userId)
3118 if ($relation ===
null)
3122 if ($relation->getUser()->isBot())
3124 IM\Bot::onJoinChat(
'chat'.$this->
getId(), [
3125 'CHAT_TYPE' => $this->
getType(),
3126 'MESSAGE_TYPE' => $this->
getType(),
3128 'USER_ID' => $this->getContext()->
getUserId(),
3129 'CHAT_ID' => $this->
getId(),
3133 "ACCESS_HISTORY" => (
int)$relation->getStartCounter() === 0,
3140 $converter =
new Converter(Converter::TO_CAMEL | Converter::UC_FIRST);
3143 foreach(
GetModuleEvents(
"im",
"OnChatUserAddEntityType".$eventCode,
true) as $arEvent)
3146 'CHAT_ID' => $this->
getId(),
3147 'NEW_USERS' => $usersToAdd,
3157 if ($userRelation && !$relations->hasUser(
$userId, $this->getId()))
3159 $relations[] = $userRelation;
3162 if ($userRelation ===
null)
3167 if (!
$config->skipCheckReason && $userRelation->getReason() !== Reason::DEFAULT)
3169 return (
new Result())->addError(
new UserError(UserError::DELETE_FROM_STRUCTURE_SYNC));
3177 $userRelation->delete();
3195 $relation = $relations->getByUserId(
$userId, $this->
getId());
3196 if ($relation ===
null)
3201 $relation->markAsHidden(
true)->save();
3217 || !$this->needToSendMessageUserDelete()
3218 || $this->getChatParams()->get(Params::USER_DELETE_MESSAGE_DISABLED)?->getValue() ??
false
3219 || $this->getEntityType() ===
'ANNOUNCEMENT'
3237 'TO_CHAT_ID' => $this->
getId(),
3239 'FROM_USER_ID' => $this->getContext()->getUserId(),
3241 'RECENT_ADD' => $skipRecent ?
'N' :
'Y',
3242 'PARAMS' => [
'CODE' =>
'CHAT_LEAVE',
'NOTIFY' =>
'N'],
3244 'SKIP_USER_CHECK' =>
'Y',
3245 'SKIP_COUNTER_INCREMENTS' =>
'Y',
3251 if (!
$config->withNotification)
3261 $gender = $this->getContext()->getUser()->getGender();
3262 $userName = $this->getContext()->getUser()->getName();
3263 $userName =
"[USER={$this->getContext()->getUserId()}]{$userName}[/USER]";
3265 $notificationCallback = fn (?
string $languageId =
null) => Loc::getMessage(
3266 'IM_CHAT_KICK_NOTIFICATION_'. $gender,
3271 $notificationFields = [
3273 'FROM_USER_ID' => 0,
3275 'NOTIFY_MODULE' =>
'im',
3277 'NOTIFY_MESSAGE' => $notificationCallback,
3279 CIMNotify::Add($notificationFields);
3284 $currentUser = $this->getContext()->getUser();
3285 $currentUserId = $this->getContext()->getUserId();
3287 if (!$currentUser->isExist())
3292 if ($currentUserId === $deletedUserId)
3294 return Loc::getMessage(
3295 "IM_CHAT_LEAVE_{$currentUser->getGender()}_MSGVER_1",
3296 [
'#USER_ID#' => $currentUserId]
3300 return Loc::getMessage(
3301 "IM_CHAT_KICK_{$currentUser->getGender()}_MSGVER_1",
3302 [
'#CURRENT_USER_ID#' => $currentUserId,
'#DELETED_USER_ID#' => $deletedUserId]
3308 \CIMContactList::DeleteRecent($this->
getId(),
true, $deletedUserId,
$config->withoutRead);
3314 $deletedUser->getType() === UserType::EXTRANET
3315 && $this->getExtranet()
3316 && !UserCollection::hasUserByType($userIds, UserType::EXTRANET)
3323 $deletedUser->getType() === UserType::COLLABER
3324 && $this->containsCollaber()
3325 && !UserCollection::hasUserByType($userIds, UserType::COLLABER)
3328 $this->
getChatParams()->deleteParam(Params::CONTAINS_COLLABER);
3331 if (AIHelper::containsCopilotBot([$deletedUserId]) && $this->
containsCopilot())
3340 self::cleanAccessCache($this->
getId());
3350 CIMContactList::CleanChatCache(
$userId);
3358 IM\Bot::onLeaveChat(
'chat'.$this->
getId(), [
3359 'CHAT_TYPE' => $this->
getType(),
3360 'MESSAGE_TYPE' => $this->
getType(),
3362 'USER_ID' => $this->getContext()->
getUserId(),
3371 $converter =
new Converter(Converter::TO_CAMEL | Converter::UC_FIRST);
3373 foreach(
GetModuleEvents(
"im",
"OnChatUserDeleteEntityType".$eventCode,
true) as $arEvent)
3376 'CHAT_ID' => $this->
getId(),
3382 $eventParams = [
'chatId' => $this->
getId(),
'userIds' => [
$userId]];
3389 if (!\
Bitrix\
Main\Loader::includeModule(
'pull'))
3401 $authorRelation = $relations->getByUserId($currentAuthorId, $this->
getId());
3402 if ($authorRelation !==
null)
3404 $authorRelation->setManager(
false);
3406 $otherRealUserRelation = $relations->filter(
static function (
Relation $relation) use ($currentAuthorId) {
3407 $user = $relation->getUser();
3409 return $user->getId() !== $currentAuthorId
3410 &&
$user->isActive()
3412 && !
$user->isExtranet()
3413 && !
$user->isConnector()
3417 if (!$otherRealUserRelation instanceof
Relation)
3422 $this->
setAuthorId($otherRealUserRelation->getUserId());
3423 $otherRealUserRelation->setManager(
true);
3424 $relations->save(
true);
3427 public function setManagers(
array $managerIds): self
3429 if (!$this->getChatId() || empty($managerIds) || !
count($managerIds))
3434 $managerIds = filter_var(
3436 FILTER_VALIDATE_INT,
3438 'flags' => FILTER_REQUIRE_ARRAY,
3439 'options' => [
'min_range' => 1],
3443 foreach ($managerIds as
$key => $managerId)
3445 if (!is_int($managerId))
3447 unset($managerIds[
$key]);
3451 $relations = $this->getRelations();
3454 $unsetManagerIds = [];
3456 foreach ($relations as $relation)
3458 if (in_array($relation->getUserId(), $managerIds,
true))
3460 $relationIds[] = $relation->getPrimaryId();
3462 elseif ($relation->getManager())
3464 $unsetManagerIds[] = $relation->getPrimaryId();
3469 if ($unsetManagerIds)
3471 RelationTable::updateMulti(
3479 RelationTable::updateMulti(
3495 Loc::loadMessages(__FILE__);
3500 $this->defaultSaveContext(
$context);
3518 return (
new \
Bitrix\
Im\
V2\
Message($startMessageId))->setChatId($this->
getId())->setMessageId($startMessageId);
3523 if ($this->isFilledNonCachedData)
3529 $this->isFilledNonCachedData =
true;
3541 return Im\V2\Chat\EntityLink::getInstance($this);
3559 'manageUi' => mb_strtolower($this->
getManageUI()),
3586 'containsCollaber' => (bool)$this->
getChatParams()->get(Params::CONTAINS_COLLABER)?->getValue(),
3587 'id' => $this->
getId(),
3592 'messageType' => $this->
getType(),
3593 'role' => mb_strtolower($this->
getRole()),
3598 'isNew' => $this->
isNew(),
3603 if (
$option[
'CHAT_WITH_DATE_MESSAGE'] ??
false)
3607 if (
$option[
'CHAT_SHORT_FORMAT'] ??
false)
3612 $additionalFields = [
3632 'id' => $this->
getId(),
3640 'contains_collaber' => (bool)$this->
getChatParams()->get(Params::CONTAINS_COLLABER)?->getValue(),
3657 'isNew' => $this->
isNew(),
3658 'message_type' => $this->
getType(),
3659 'ai_provider' =>
null,
3680 return [$this->getContext()->getUserId()];
3693 $list[$relation->getUserId()] = $relation->getNotifyBlock();
3701 if ($selfRelation ===
null)
3706 if ($selfRelation->getNotifyBlock() ??
false)
3708 return [$this->getContext()->getUserId()];
3738 if ($selfRelation ===
null)
3743 return $selfRelation->getUnreadId() ?? 0;
3749 if ($selfRelation ===
null)
3754 return $selfRelation->getLastId() ?? 0;
3766 ->setTitle(mb_substr($this->
getTitle() ??
'', 0, 255))
3767 ->setUserList($this->getUserNamesForIndex())
3783 ->setUserList($this->getUserNamesForIndex())
3790 private function getUserNamesForIndex():
array
3795 foreach ($relations as $relation)
3797 $users[] = $relation->getUser()->getName() ??
'';
3825 private function hideChat():
Result
3829 if (!$this->getChatId())
3835 foreach($this->getRelations() as $relation)
3837 \CIMContactList::DeleteRecent($this->getChatId(),
true, $relation->getUserId());
3841 $pushList[] = $relation->getUserId();
3847 && \
Bitrix\Main\Loader::includeModule(
"pull")
3851 'module_id' =>
'im',
3852 'command' =>
'chatHide',
3855 'dialogId' =>
'chat' . $this->getChatId(),
3856 'chatId' => $this->getId(),
3857 'lines' => $this->getType() === self::IM_TYPE_OPEN_LINE,
3868 $currentUser = $this->getContext()->getUser();
3870 $code =
"IM_{$type}_AVATAR_CHANGE_{$currentUser->getGender()}";
3872 $messageText = Loc::getMessage(
3877 if ($messageText ===
'')
3882 \CIMChat::AddMessage([
3883 "TO_CHAT_ID" => $this->
getId(),
3884 "MESSAGE" => $messageText,
3885 "FROM_USER_ID" => $this->getContext()->
getUserId(),
3887 "RECENT_ADD" => $skipRecent ?
'N' :
'Y',
3889 "CODE" =>
'CHAT_LEAVE',
3893 "SKIP_USER_CHECK" =>
"Y",
3902 && $this->
getChatParams()->
get(Params::USER_DELETE_MESSAGE_DISABLED)?->getValue() !==
true
3906 $this->
getChatParams()->addParamByName(Params::USER_DELETE_MESSAGE_DISABLED,
true);
3913 return Option::get(
'im',
'chat_user_deletion_message_disabled',
'N') ===
'Y';
3918 $userCount = self::MAX_USERS_TO_DISABLE_DELETE_MESSAGE;
3920 \CIMChat::AddMessage([
3921 'TO_CHAT_ID' => $this->
getId(),
3922 'MESSAGE' => Loc::getMessage(
'IM_CHAT_OVERFLOW_DELETE_MESSAGE', [
'#USER_COUNT#' =>
$userCount]),
3924 'RECENT_ADD' => $skipRecent ?
'N' :
'Y',
3926 'SKIP_USER_CHECK' =>
'Y',
3927 'SKIP_COUNTER_INCREMENTS' =>
'Y',
3941 $options = \CIMChat::GetChatOptions();
3944 $defaultAllowed = (bool)($chatOptions[
'DEFAULT'][
$action] ??
true);
3951 return $defaultAllowed;
3956 $userRights = $this->
getRole();
3957 $userId = $this->getContext()->getUserId();
3958 $action = Im\V2\Permission::specifyAction(
$action, $this, $target);
3961 $actionGroup = Im\V2\Permission\ActionGroup::tryFromAction(
$action);
3963 $manageRights = match ($actionGroup)
3965 Permission\ActionGroup::ManageUi => $this->
getManageUI(),
3971 default => Chat::ROLE_GUEST,
3974 return Im\V2\Permission::compareRole($userRights, $manageRights)
3975 && Im\V2\Permission::compareRole($userRights, $rightByType)
3976 && Im\V2\Permission::canDoActionByUserType(
$userId,
$action, $target)
3981 $chat = self::$chatStaticCache[$id];
3982 $chat?->onAfterOrmUpdate(
$fields);
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
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 getType($chatData, bool $camelCase=true)
static getColorByNumber($number)
static isSafeColor($code)
static getCodeByNumber($number)
static toJson($array, $camelCase=true)
static getChatId($dialogId, $userId=null)
static delete($dialogId, $userId=null)
static updateIndexRecord(ChatIndex $index)
static addIndexRecord(ChatIndex $index)
static readAll(int $userId)
static isUnread(int $userId, string $itemType, string $dialogId)
static unread($dialogId, $unread, $userId=null, ?int $markedId=null, ?string $itemTypes=null)
static getMarkedId(int $userId, string $itemType, string $dialogId)
static getUsersOutOfRecent(\Bitrix\Im\V2\Chat $chat)
static decodeEmoji($text)
static getInstance($userId=null)
const TEXT_FIELD_DISABLED
static sendSharedPull(array $pull)
static loadWithoutChat(array $source)
setLastMessageId(int $lastMessageId)
read(bool $onlyRecent=false, bool $byEvent=false)
setChatParams(array $chatParams=[])
updateCountersAfterMessageSend(Message $message, SendingConfig $sendingConfig)
static getRestEntityName()
sendNotificationUserDelete(int $userId, DeleteUserConfig $config)
getExtendedType(bool $forRest=true)
setPrimaryId(int $primaryId)
const ENTITY_TYPE_LIVECHAT
setRelations(RelationCollection $relations)
getManageMessagesAutoDelete()
Registry $messageRegistry
int $messagesAutoDeleteDelay
setCanPost(string $canPost)
updateStateAfterMessageSend(Message $message, SendingConfig $sendingConfig)
checkAccessInternal(int $userId)
getFieldsForRecent(int $userId, Message $message)
sendMessageUsersAdd(array $usersToAdd, AddUsersConfig $config)
sendMessage(Message $message, ?SendingConfig $sendingConfig=null)
getValidUsersToAdd(array $userIds)
getRecentSectionsForGuest()
setDialogId(string $dialogId)
onAfterMessageUpdate(Message $message)
toRestFormat(array $option=[])
prepareMessage(Message $message)
clearLegacyCache(int $userId)
const MANAGE_RIGHTS_MEMBER
getDefaultLastMessageStatus()
setUserIds(?array $userIds)
setAvatarId(?int $avatarId)
getRelationByReason(Reason $reason)
const ENTITY_TYPE_GENERAL
getUpdatedFieldsForRecent(Message $message)
setMarkedId(?int $markedId)
updateMessage(Message $message)
sendPushUserDelete(int $userId, RelationCollection $oldRelations)
static cleanAccessCache(int $chatId)
canDisableUserDeleteMessage()
setExtranet(?bool $extranet)
getMessageAutoDeleteConfigs()
sendPushUpdateMessage(Message $message)
setManageUsersDelete(string $manageUsersDelete)
getAvatar(bool $addBlankPicture=false, bool $withDomain=false)
sendPushReadSelf(MessageCollection $messages, int $lastId, int $counter)
static array $chatStaticCache
setEntityData3(?string $entityData3)
updateStateAfterRelationsAdd(array $usersToAdd)
needToSendMessageUserDelete()
static getSharedChatsWithUser(int $userId, int $limit=50, int $offset=0, ?int $currentUserId=null)
getColor(bool $forRest=false)
getUsersForPush(bool $skipBot=false, bool $skipSelf=true)
setEntityData1(?string $entityData1)
static getDialogIdByContextId(string $contextId, ?int $userId=null)
processSendToOtherChat(Message $message, SendingConfig $config)
const ENTITY_TYPE_VIDEOCONF
const IM_TYPE_AI_ASSISTANT
Im V2 Relation ChatRelations $chatRelations
getPopupData(array $excludedList=[])
__construct($source=null)
updateRecentItems(Message $message)
checkAllowedAction(string $action)
setParentChatId(int $parentChatId)
getPushService(Message $message, SendingConfig $config)
getRelationByUserId(int $userId)
getUserDeleteMessageText(int $deletedUserId)
setPinMessageId(?int $pinMessageId)
prepareAliasToLoad($alias)
const MANAGE_RIGHTS_MANAGERS
readTo(Message $message, bool $byEvent=false)
string $manageUsersDelete
const ENTITY_TYPE_PRIVATE_AI_ASSISTANT
addUsers(array $userIds, AddUsersConfig $config=new AddUsersConfig())
setDateCreate(?DateTime $dateCreate)
setPrevMessageId(int $prevMessageId)
onBeforeMessageSend(Message $message, SendingConfig $config)
setMessageCount(int $messageCount)
bool $isFilledNonCachedData
sendEventRead(int $startId, int $endId, int $counter, bool $byEvent)
getMuteList(bool $fullList=false)
getDefaultMessagesAutoDeleteDelay()
Im V2 Call CallToken $callToken
isValidToAdd(int $userId)
sendEventUserDelete(int $userId)
readAllMessages(bool $byEvent=false)
const IM_TYPE_AI_ASSISTANT_ENTITY
sendEventUsersAdd(array $usersToAdd)
setEntityData2(?string $entityData2)
static updateStateAfterOrmEvent(int $id, array $fields)
getLastMessageViewsByGroups()
sendPushReadOpponent(MessageCollection $messages, int $lastId)
static readAllChats(int $userId)
const MANAGE_RIGHTS_OWNER
setDiskFolderId(?int $diskFolderId)
readMessages(?MessageCollection $messages, bool $byEvent=false)
string $lastMessageStatus
getAccessCodesForDiskFolder()
setManageUI(string $manageUI)
const EXTRANET_CAN_SEE_HISTORY
markFilledNonCachedData(bool $isFilledNonCachedData)
sendPushRead(MessageCollection $messages, int $lastId, int $counter)
const ENTITY_TYPE_GENERAL_CHANNEL
setManageSettings(string $manageSettings)
getDefaultManageSettings()
setAliasName(string $aliasName)
insertRecent(array $fields)
setMessagesAutoDeleteDelay(int $messagesAutoDeleteDelay)
setLastMessageStatus(?string $lastMessageStatus)
getMessage(int $messageId)
setEntityType(?string $entityType)
getStartId(?int $userId=null)
sendMessageOnUserDeleteMessageDisabled(bool $skipRecent)
resolveRelationConflicts(array $userIds, AddUsersConfig $config)
setCallType(?int $callType)
updateChatAfterMessageSend(Message $message)
disableUserDeleteMessage(bool $skipRecent=false)
getManagerList(bool $fullList=true)
setParentMessageId(int $messageId)
setEntityId(?string $entityId)
RelationProvider $relationProvider
deleteMessage(Message $message)
static getInstance(?int $chatId)
RecentConfigManager $recentConfigManager
setManageUsersAdd(string $manageUsersAdd)
onAfterMessageSend(Message $message, SendingService $sendingService)
setUserCounter(?int $userCounter)
static fillSelfRelations(array $chats, ?int $userId=null)
getMentionService(SendingConfig $config)
updateRecentAfterMessageSend(Message $message, SendingConfig $config)
getDefaultManageMessagesAutoDelete()
prepareMessageParamsFromUserDelete(string $message, bool $skipRecent)
getRelationsByUserIds(array $userIds)
getDefaultManageMessages()
sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations)
sendMessageUserDelete(int $userId, DeleteUserConfig $config)
setManageMessages(string $manageMessages)
setDescription(?string $description)
getDefaultManageUsersAdd()
setContext(?Context $context)
sendMessageUpdateAvatar(bool $skipRecent=false)
setCallNumber(?string $callNumber)
canUserAutoJoin(?int $userId=null)
addUsersToRelation(array $usersToAdd, AddUsersConfig $config)
getLoadContextMessage(bool $ignoreMark=false)
static cleanCache(int $id, bool $cleanStaticCache=true)
deleteUser(int $userId, DeleteUserConfig $config=new DeleteUserConfig())
getDialogId(?int $contextUserId=null)
setDiskFolder(?Folder $folder)
filterUsersToMentionAnchor(array $userIds)
updateStateAfterMembersAdd(array $newMembers)
setUserCount(int $userCount)
TextFieldEnabled $textFieldEnabled
static find(array $params, ?Context $context=null)
createRelation(int $userId, AddUsersConfig $config)
updateStateAfterUserDelete(int $deletedUserId, DeleteUserConfig $config)
updateRelationsAfterMessageSend(Message $message)
checkAccess(int|User|null $user=null)
setManageMessagesAutoDelete(string $manageMessagesAutoDelete)
getDefaultManageUsersDelete()
filterUsersToMention(array $userIds)
const ENTITY_TYPE_FAVORITE
addToRecent(array $users, Message $message)
setAuthorId(int $authorId)
const IM_TYPE_OPEN_CHANNEL
getMessagesAutoDeleteDelay()
getRelationsForSendMessage()
static mirrorDataEntityFields()
const MAX_USERS_TO_DISABLE_DELETE_MESSAGE
canDo(Action $action, mixed $target=null)
logToSyncAfterMessageSend(Message $message)
join(bool $withMessage=true)
isCounterIncrementAllowed()
static getInstance(?int $id)
fireEventAfterMessageSend(Chat $chat, Message $message)
updateMessageUuid(Message $message)
static getInstance(int $chatId)
static getStartId(int $userId, int $chatId)
static find(array $filter, array $order=[], ?int $limit=null, ?Context $context=null, array $select=self::COMMON_FIELDS)
static getConnection($name="")
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static ChangeFolderMembers($chatId, $userId, $append=true)
static GetStorage(?int $chatId=null)
static GetMaxFileId($chatId)
static GetStorageId(?int $chatId=null)
static GetNotifyAccess($userId, $moduleId, $eventId, $clientId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
const IM_MESSAGE_OPEN_LINE
ExecuteModuleEventEx($arEvent, $arParams=[])
htmlspecialcharsback($str)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
<? endif;?> window document title
if(empty($signedUserToken)) $key
if(empty($decryptedData)) $storage
</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']
if( $fieldsExist) if($parametricFieldsExist) $commonFields