16 private $bHideLink =
false;
21 $this->user_id = intval($user_id);
22 if ($this->user_id == 0)
23 $this->user_id = intval(
$USER->GetID());
25 $this->bHideLink =
true;
30 if (!isset(
$arFields[
'MESSAGE_TYPE']) || !in_array(
$arFields[
'MESSAGE_TYPE'], CIMChat::getGroupTypesExtra()))
49 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
51 C.TITLE as CHAT_TITLE,
52 C.COLOR as CHAT_COLOR,
53 C.AVATAR as CHAT_AVATAR
56 INNER JOIN b_im_relation R ON R.CHAT_ID = M.CHAT_ID AND R.USER_ID = ".$this->user_id.
"
57 INNER JOIN b_im_chat C ON C.ID = M.CHAT_ID
69 $files = CIMMessageParam::Get($id,
'FILE_ID');
82 \Bitrix\Im\Model\MessageTable::update($id,
array(
83 "MESSAGE_OUT" => $messageOut,
93 $bSpeedCheck = isset(
$arParams[
'SPEED_CHECK']) &&
$arParams[
'SPEED_CHECK'] ==
'N'?
false:
true;
95 $loadDepartment = isset(
$arParams[
'LOAD_DEPARTMENT']) &&
$arParams[
'LOAD_DEPARTMENT'] ==
'N'?
false:
true;
96 $bTimeZone = isset(
$arParams[
'USE_TIME_ZONE']) &&
$arParams[
'USE_TIME_ZONE'] ==
'N'?
false:
true;
97 $bGroupByChat = isset(
$arParams[
'GROUP_BY_CHAT']) &&
$arParams[
'GROUP_BY_CHAT'] ==
'Y'?
true:
false;
98 $bUserLoad = isset(
$arParams[
'USER_LOAD']) &&
$arParams[
'USER_LOAD'] ==
'N'?
false:
true;
99 $bFileLoad = isset(
$arParams[
'FILE_LOAD']) &&
$arParams[
'FILE_LOAD'] ==
'N'?
false:
true;
100 $arExistUserData = isset(
$arParams[
'EXIST_USER_DATA']) && is_array(
$arParams[
'EXIST_USER_DATA'])?
$arParams[
'EXIST_USER_DATA']: Array();
102 $arMessages = Array();
103 $arUnreadMessage = Array();
104 $arUsersMessage = Array();
107 'message' => Array(),
108 'unreadMessage' => Array(),
109 'usersMessage' => Array(),
112 'userInGroup' => Array(),
116 $bLoadMessage = $bSpeedCheck? CIMMessenger::SpeedFileExists($this->user_id,
IM_SPEED_MESSAGE):
false;
118 if (!$bLoadMessage || ($bLoadMessage && intval(
$count) > 0))
148 $arLastMessage = Array();
150 $arMessageId = Array();
151 $arMessageChatId = Array();
156 CTimeZone::Disable();
164 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
167 R1.USER_ID as R1_USER_ID,
168 M.AUTHOR_ID as R2_USER_ID
170 LEFT JOIN b_im_chat C ON C.ID = M.CHAT_ID
171 INNER JOIN b_im_relation R1 ON M.CHAT_ID = R1.CHAT_ID AND R1.USER_ID != M.AUTHOR_ID
172 INNER JOIN b_im_message_unread MU ON M.ID = MU.MESSAGE_ID AND MU.USER_ID = " . $this->user_id .
"
178 $strSql =
$DB->TopSql($strSql, 500);
187 $diskFolderId =
$arRes[
'DISK_FOLDER_ID'];
188 $arUsers[] =
$arRes[
'R1_USER_ID'];
189 $arUsers[] =
$arRes[
'R2_USER_ID'];
190 if ($this->user_id ==
$arRes[
'AUTHOR_ID'])
194 $convId =
$arRes[
'TO_USER_ID'];
200 $convId =
$arRes[
'FROM_USER_ID'];
203 $arMessages[
$arRes[
'ID']] = Array(
205 'chatId' =>
$arRes[
'CHAT_ID'],
206 'senderId' =>
$arRes[
'FROM_USER_ID'],
207 'recipientId' =>
$arRes[
'TO_USER_ID'],
209 'system' =>
$arRes[
'NOTIFY_EVENT'] ==
'private'?
'N':
'Y',
210 'text' =>
$arRes[
'MESSAGE'],
214 $arMessages[
$arRes[
'ID']][
'conversation'] = $convId;
215 $arMessages[
$arRes[
'ID']][
'unread'] = $this->user_id !=
$arRes[
'AUTHOR_ID']?
'Y':
'N';
219 $arMessages[
$arRes[
'ID']][
'conversation'] = $convId;
220 $arUsersMessage[$convId][] =
$arRes[
'ID'];
226 if (!isset($arLastMessage[$convId]) || $arLastMessage[$convId] <
$arRes[
"ID"])
227 $arLastMessage[$convId] =
$arRes[
"ID"];
229 $arMessageId[] =
$arRes[
'ID'];
232 $params = CIMMessageParam::Get($arMessageId);
235 foreach ($arMessageChatId as $chatId =>
$messages)
246 $files[$fileId] = $fileId;
252 foreach ($arMessageFiles as
$key => $value)
266 if (!empty($arMessages))
268 foreach ($arMark as $chatId => $lastSendId)
274 foreach ($arMessages as
$key => $value)
276 $arMessages[$arLastMessage[$value[
'conversation']]][
'counter']++;
277 if ($arLastMessage[$value[
'conversation']] != $value[
'id'])
279 unset($arMessages[
$key]);
286 $arUsersMessage[$value[
'conversation']][] = $value[
'id'];
288 if ($value[
'unread'] ==
'Y')
289 $arUnreadMessage[$value[
'conversation']][] = $value[
'id'];
291 unset($arMessages[
$key][
'conversation']);
292 unset($arMessages[
$key][
'unread']);
298 foreach ($arMessages as
$key => $value)
303 if ($value[
'params'][
'NOTIFY'] ===
'N' || is_array($value[
'params'][
'NOTIFY']) && !in_array($this->user_id, $value[
'params'][
'NOTIFY']))
307 else if ($this->user_id != $value[
'senderId'])
309 $arUnreadMessage[$value[
'conversation']][] = $value[
'id'];
312 unset($arMessages[
$key][
'conversation']);
318 $arResult[
'unreadMessage'] = $arUnreadMessage;
319 $arResult[
'usersMessage'] = $arUsersMessage;
321 if ($bUserLoad && !empty($arUsers))
323 $arUserData = CIMContactList::GetUserData(Array(
'ID' => array_diff(array_unique($arUsers), $arExistUserData),
'DEPARTMENT' => ($loadDepartment?
'Y':
'N')));
324 $arResult[
'users'] = $arUserData[
'users'];
325 $arResult[
'userInGroup'] = $arUserData[
'userInGroup'];
334 $arResult[
'countMessage'] = CIMMessenger::GetMessageCounter($this->user_id,
$arResult);
341 $arResult[
'countMessage'] = CIMMessenger::GetMessageCounter($this->user_id,
$arResult);
347 function GetLastMessage($toUserId, $fromUserId =
false, $loadUserData =
false, $bTimeZone =
true, $limit =
true)
351 $fromUserId = intval($fromUserId);
352 if ($fromUserId <= 0)
353 $fromUserId = $this->user_id;
355 $toUserId = intval($toUserId);
358 $GLOBALS[
"APPLICATION"]->ThrowException(
GetMessage(
"IM_ERROR_EMPTY_USER_ID"),
"ERROR_TO_USER_ID");
366 $limitFetchMessages = 30;
367 $blockNotify =
false;
369 $arMessages = Array();
370 $arUsersMessage = Array();
371 $arMessageId = Array();
372 $arUnreadMessages = Array();
377 CTimeZone::Disable();
379 if ($toUserId == $fromUserId)
382 $chatId = (int)$chat->GetPersonalChat();
387 SELECT R1.CHAT_ID, R1.START_ID, R1.LAST_ID, R2.LAST_ID as LAST_READ_ID, R1.NOTIFY_BLOCK
388 FROM b_im_relation R1
389 INNER JOIN b_im_relation R2 on R2.CHAT_ID = R1.CHAT_ID
391 R1.USER_ID = ".$fromUserId.
"
393 AND R2.USER_ID = ".$toUserId.
"
401 $chatId = intval(
$arRes[
'CHAT_ID']);
402 $startId = intval(
$arRes[
'START_ID']);
403 $readService = new \Bitrix\Im\V2\Message\ReadService($fromUserId);
404 $opponentReadService = new \Bitrix\Im\V2\Message\ReadService($toUserId);
407 $lastIdInChat = $readService->getLastMessageIdInChat($chatId);
410 ->where(
'ID',
'>=', $startId)
412 ->where(
'ID',
'<=', $lastIdInChat)
413 ->where(
'CHAT_ID', $chatId)
415 $messageCount = \Bitrix\Im\Model\MessageTable::getCount($messageCountFilter);
417 $lastReadId = (int)
$arRes[
'LAST_READ_ID'];
418 $lastRead = $opponentReadService->getViewedService()->getDateViewedByMessageId($lastReadId ?? 0);
419 $limitFetchMessages = max($messageCount, 30);
420 $blockNotify =
$arRes[
'NOTIFY_BLOCK'] !==
'N';
429 if (
$DB->type ==
"MSSQL")
431 $sqlLimit =
" AND M.DATE_CREATE > dateadd(day, -30, getdate())";
435 $sqlLimit =
" AND M.DATE_CREATE > SYSDATE-30";
441 $sqlLimit =
" AND M.DATE_CREATE > ". $helper->addDaysToDateTime(-30);
446 CTimeZone::Disable();
452 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
456 WHERE M.CHAT_ID = ".$chatId.
" #LIMIT#
457 ORDER BY M.DATE_CREATE DESC, M.ID DESC
459 $strSql =
$DB->TopSql($strSql, $limitFetchMessages);
465 $dbRes =
$DB->Query(str_replace(
"#LIMIT#", $sqlLimit, $strSql));
469 $dbRes =
$DB->Query(str_replace(
"#LIMIT#",
"", $strSql));
474 if (
$arRes[
'ID'] < $startId)
477 if ($fromUserId ==
$arRes[
'AUTHOR_ID'])
479 $arRes[
'TO_USER_ID'] = $toUserId;
480 $arRes[
'FROM_USER_ID'] = $fromUserId;
481 $convId =
$arRes[
'TO_USER_ID'];
485 $arRes[
'TO_USER_ID'] = $fromUserId;
486 $arRes[
'FROM_USER_ID'] = $toUserId;
487 $convId =
$arRes[
'FROM_USER_ID'];
490 $arMessages[
$arRes[
'ID']] = Array(
492 'chatId' =>
$arRes[
'CHAT_ID'],
493 'senderId' =>
$arRes[
'FROM_USER_ID'],
494 'recipientId' =>
$arRes[
'TO_USER_ID'],
495 'system' =>
$arRes[
'NOTIFY_EVENT'] ==
'private'?
'N':
'Y',
501 $arMessageId[] =
$arRes[
'ID'];
502 $arUsersMessage[$convId][] =
$arRes[
'ID'];
505 $arUnreadMessages[$convId][] =
$arRes[
'ID'];
509 $params = CIMMessageParam::Get($arMessageId);
517 mb_strlen($arMessages[
$messageId][
'text']) <= 0
518 && !isset($param[
'FILE_ID'])
519 && !isset($param[
'KEYBOARD'])
520 && !isset($param[
'ATTACH'])
524 $arMessages[
$messageId][
'params'][
'IS_DELETED'] =
'Y';
527 if (isset($param[
'FILE_ID']))
529 foreach ($param[
'FILE_ID'] as $fileId)
539 $arUserChatBlockStatus = Array();
541 $arUserChatBlockStatus[$chatId][$fromUserId] =
'Y';
545 'message' => $arMessages,
546 'usersMessage' => $arUsersMessage,
547 'unreadMessage' => $arUnreadMessages,
549 'userInGroup' => Array(),
550 'files' => $arChatFiles,
551 'userChatBlockStatus' => $arUserChatBlockStatus
556 $arResult[
'readedList'][$toUserId] = Array(
557 'messageId' => $lastReadId,
562 if (is_array($loadUserData) || is_bool($loadUserData) && $loadUserData ==
true)
565 if (is_array($loadUserData) && $loadUserData[
'DEPARTMENT'] ==
'N')
566 $bDepartment =
false;
568 $ar = CIMContactList::GetUserData(
array(
569 'ID' => Array($fromUserId, $toUserId),
570 'DEPARTMENT' => ($bDepartment?
'Y':
'N'),
572 'SHOW_ONLINE' =>
'Y',
593 $fromUserId = isset(
$arParams[
'FROM_USER_ID']) && intval(
$arParams[
'FROM_USER_ID'])>0? intval(
$arParams[
'FROM_USER_ID']): $this->user_id;
596 $bTimeZone = isset(
$arParams[
'USE_TIME_ZONE']) &&
$arParams[
'USE_TIME_ZONE'] ==
'N'?
false:
true;
598 $arToUserId = Array();
599 if (is_array($toUserId))
602 $arToUserId[] = intval(
$userId);
606 $arToUserId[] = intval($toUserId);
608 if (empty($arToUserId))
614 if (
$DB->type ==
"MSSQL")
616 $sqlLimit =
" AND M.DATE_CREATE > dateadd(day, -".$limit.
", getdate())";
620 $sqlLimit =
" AND M.DATE_CREATE > SYSDATE-".$limit;
628 $sqlLimit =
" AND M.DATE_CREATE > ". $helper->addDaysToDateTime(-1 * $limit);
633 CTimeZone::Disable();
639 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
641 R1.USER_ID as R1_USER_ID,
642 R2.USER_ID as R2_USER_ID
643 FROM b_im_relation R1
644 INNER JOIN b_im_relation R2 on R2.CHAT_ID = R1.CHAT_ID
645 INNER JOIN b_im_message M ON M.ID >= R1.START_ID
646 AND M.ID >= R1.LAST_ID
647 AND M.ID >= R2.LAST_ID
648 AND M.CHAT_ID = R1.CHAT_ID
651 R1.USER_ID = ".$fromUserId.
"
652 AND R2.USER_ID IN (".implode(
",",$arToUserId).
")
654 ".(
$order ==
'DESC'?
"ORDER BY M.DATE_CREATE DESC, M.ID DESC":
"");
658 $arMessages = Array();
662 if ($fromUserId ==
$arRes[
'AUTHOR_ID'])
666 $convId =
$arRes[
'TO_USER_ID'];
672 $convId =
$arRes[
'FROM_USER_ID'];
675 if (!isset($arMessages[$convId]) || (isset($arMessages[$convId]) && $arMessages[$convId][
'date'] <
$arRes[
'DATE_CREATE']))
678 $arMessages[$convId] = Array(
680 'senderId' =>
$arRes[
'FROM_USER_ID'],
681 'recipientId' =>
$arRes[
'TO_USER_ID'],
683 'text' =>
$arRes[
'MESSAGE']
687 foreach ($arMessages as
$key => $value)
690 $arMessages[
$key] = $value;
705 $mailService = new \Bitrix\Im\V2\Mail();
707 $unsendIds = $mailService->getMessageIdsToSend();
709 if (empty($unsendIds))
714 $implodeUnsendIds = implode(
',', $unsendIds);
716 CTimeZone::Disable();
723 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
725 R.USER_ID as TO_USER_ID,
726 U1.ACTIVE as TO_USER_ACTIVE,
727 U1.LOGIN as TO_USER_LOGIN,
728 U1.NAME as TO_USER_NAME,
729 U1.LAST_NAME as TO_USER_LAST_NAME,
730 U1.EMAIL as TO_USER_EMAIL,
731 U1.LID as TO_USER_LID,
732 U1.TIME_ZONE as TIME_ZONE,
733 U1.EXTERNAL_AUTH_ID as TO_EXTERNAL_AUTH_ID,
734 M.AUTHOR_ID as FROM_USER_ID,
735 U2.LOGIN as FROM_USER_LOGIN,
736 U2.NAME as FROM_USER_NAME,
737 U2.LAST_NAME as FROM_USER_LAST_NAME,
738 U2.EXTERNAL_AUTH_ID as FROM_EXTERNAL_AUTH_ID
740 INNER JOIN b_im_message M ON M.CHAT_ID = R.CHAT_ID AND IMPORT_ID IS NULL AND R.USER_ID != M.AUTHOR_ID AND M.ID IN ({$implodeUnsendIds})
741 LEFT JOIN b_user U1 ON U1.ID = R.USER_ID
742 LEFT JOIN b_user U2 ON U2.ID = M.AUTHOR_ID
743 ".(
$order ==
"DESC"?
"ORDER BY M.DATE_CREATE DESC, M.ID DESC":
"").
"
749 $arMessages = Array();
763 $fromUserId = intval($fromUserId);
764 if ($fromUserId <= 0)
774 $readService = new \Bitrix\Im\V2\Message\ReadService($this->user_id);
776 $startId = $readService->getLastIdByChatId($chat->getChatId());
778 $viewedMessages = [];
782 $message = new \Bitrix\Im\V2\Message();
783 $message->setMessageId((
int)
$lastId)->setChatId($chat->getChatId())->setChat($chat);
784 $readResult = $readService->readTo(
$message);
785 $counter = $readResult->getResult()[
'COUNTER'];
786 $viewedMessages = $readResult->getResult()[
'VIEWED_MESSAGES'];
790 $counter = $readService->readAllInChat($chat->getChatId())->getResult()[
'COUNTER'];
797 $endId = $readService->getLastIdByChatId($chat->getChatId());
799 if (CModule::IncludeModule(
"pull"))
801 CPushManager::DeleteFromQueueBySubTag($this->user_id,
'IM_MESS');
805 'command' =>
'readMessage',
807 'dialogId' => $fromUserId,
808 'chatId' => $chat->getChatId(),
809 'senderId' => $this->user_id,
811 'userId' => $fromUserId,
816 'viewedMessages' => $viewedMessages,
817 'counterType' => $chat->getCounterType()->value,
818 'recentConfig' => $chat->getRecentConfig()->toPullFormat(),
824 'command' =>
'readMessageOpponent',
827 'dialogId' => $this->user_id,
828 'chatId' => $chat->getChatId(),
829 'userId' => $this->user_id,
832 'date' => date(
'c', time()),
834 'viewedMessages' => $viewedMessages,
843 'DIALOG_ID' => $fromUserId,
844 'CHAT_ID' => $chat->getChatId(),
845 'CHAT_ENTITY_TYPE' =>
'USER',
846 'CHAT_ENTITY_ID' =>
'',
847 'START_ID' => $startId,
850 'USER_ID' => $this->user_id,
851 'BY_EVENT' => $byEvent
856 'DIALOG_ID' => $fromUserId,
857 'CHAT_ID' => $chat->getChatId(),
867 $fromUserId = intval($fromUserId);
868 if ($fromUserId <= 0)
884 FROM b_im_relation RF
885 INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID
886 INNER JOIN b_im_message M ON M.ID = ".$lastId.
" AND M.CHAT_ID = RT.CHAT_ID
887 WHERE RT.USER_ID = ".$this->user_id.
"
888 and RF.USER_ID = ".$fromUserId.
"
899 "UPDATE b_im_recent SET DATE_UPDATE = NOW() WHERE USER_ID = ".$this->user_id.
" AND ITEM_CID = ".intval(
$arRes[
'CHAT_ID'])
904 if (CModule::IncludeModule(
"pull"))
908 'command' =>
'unreadMessage',
911 'dialogId' => $fromUserId,
912 'chatId' => intval(
$arRes[
'CHAT_ID']),
913 'userId' => $fromUserId,
915 'counter' => (
int)$relation[
'COUNTER'],
919 'counterType' => $chat->getCounterType()->value,
920 'recentConfig' => $chat->getRecentConfig()->toPullFormat(),
922 'push' => Array(
'badge' =>
'Y'),
927 'command' =>
'unreadMessageOpponent',
930 'dialogId' => $this->user_id,
931 'chatId' => intval(
$arRes[
'CHAT_ID']),
932 'userId' => $this->user_id,
933 'chatMessageStatus' => $relation[
'CHAT_MESSAGE_STATUS'],
988 $chatId = intval($chatId);
991 $lastIdIsNull =
$lastId ===
null;
994 if ($chatId <= 0 ||
$userId <= 0)
997 $updateCounters =
false;
1000 'SELECT' => Array(
'ID',
'CHAT_ID',
'LAST_ID',
'USER_ID',
'NOTIFY_BLOCK',
'MESSAGE_TYPE'),
1004 'REAL_COUNTERS' => $lastIdIsNull?
'Y': Array(
1008 if (isset($relations[
$userId]))
1010 $relation = $relations[
$userId];
1071 $relation[
'CHAT_MESSAGE_STATUS'] = (new \Bitrix\Im\V2\Message\ReadService(
$userId))->getChatMessageStatus($chatId);
1158 $message = new \Bitrix\Im\V2\Message();
1162 if ($ownRelation ===
null)
1167 $firstUnreadMessage = \Bitrix\Im\Model\MessageTable::getList([
1170 '=CHAT_ID' => $chatId,
1174 'order' => Array(
'ID' =>
'DESC')
1177 $firstUnreadMessage = intval($firstUnreadMessage[
'ID']);
1179 UPDATE b_im_relation
1180 SET LAST_ID=(CASE WHEN LAST_ID < {$firstUnreadMessage} THEN LAST_ID ELSE {$firstUnreadMessage} END)
1181 WHERE CHAT_ID={$chatId} AND USER_ID={$userId}
1184 $readService = new \Bitrix\Im\V2\Message\ReadService(
$userId);
1185 $readService->getCounterService()->addStartingFrom(
$lastId, $ownRelation);
1187 $readService->getViewedService()->deleteStartingFrom(
$message);
1215 public static function Delete($id,
$userId =
null, $completeDelete =
false, $byEvent =
false)
1217 return CIMMessenger::Delete($id,
$userId, $completeDelete, $byEvent);
1239 $arUsers = CIMContactList::GetUserData(Array(
1244 $multidialogBot =
null;
1245 foreach ($arUsers[
'users'] as
$key =>
$user)
1248 !empty(
$user[
'bot_data'])
1249 && in_array(
$user[
'bot_data'][
'type'], [
'support24',
'network'])
1252 &&
count($arUsers[
'users']) == 2
1255 $botId = (int)
$user[
'id'];
1256 foreach ($arUsers[
'users'] as $otherUser)
1258 if ($otherUser[
'id'] != $botId)
1260 $multidialogBot = \Bitrix\ImBot\Bot\Network::getBotAsMultidialog($botId, (
int)$otherUser[
'id']);
1267 $chatType = Chat::IM_TYPE_PRIVATE;
1268 $chatEntityType =
'';
1271 $arChat = CIMChat::GetChatData(
array(
1276 $chatType = $arChat[
'chat'][
$arParams[
'TO_CHAT_ID']][
'message_type'];
1277 $chatEntityType = $arChat[
'chat'][
$arParams[
'TO_CHAT_ID']][
'entity_type'] ??
'';
1278 $extraParamContext =
$arParams[
'EXTRA_PARAMS'][
'CONTEXT'] ??
null;
1279 if (!empty($arUsers[
'users']) && $extraParamContext ==
'LIVECHAT' && CModule::IncludeModule(
'imopenlines'))
1281 [$lineId,
$userId] = explode(
'|', $arChat[
'chat'][
$arParams[
'TO_CHAT_ID']][
'entity_id']);
1282 $userCode =
'livechat|' . $lineId .
'|' .
$arParams[
'TO_CHAT_ID'] .
'|' .
$userId;
1285 foreach ($arUsers[
'users'] as
$userId => $userData)
1287 $arUsers[
'users'][
$userId] = \Bitrix\ImOpenLines\Connector::getOperatorInfo(
$arParams[
'EXTRA_PARAMS'][
'LINE_ID'],
$userId, $userCode);
1301 if (isset(
$arParams[
'FILE_TEMPLATE_ID']))
1312 || $arChat[
'chat'][
$arParams[
'TO_CHAT_ID']][
'type'] ===
'copilot'
1316 $isCopilotChat = $arChat[
'chat'][
$arParams[
'TO_CHAT_ID']][
'type'] ===
'copilot';
1317 $copilotData = self::prepareCopilotData(
$arParams, $chatId, $isCopilotChat);
1320 $additionalEntitiesAdapter = new \Bitrix\Im\V2\Rest\RestAdapter();
1321 $additionalPopupData = new \Bitrix\Im\V2\Rest\PopupData([]);
1323 $forwardInfo =
null;
1324 if (isset(
$arParams[
'PARAMS'][
'FORWARD_CONTEXT_ID']))
1326 $additionalUserId = (int)
$arParams[
'PARAMS'][
'FORWARD_USER_ID'];
1329 'id' =>
$arParams[
'PARAMS'][
'FORWARD_CONTEXT_ID'],
1330 'userId' => (int)
$arParams[
'PARAMS'][
'FORWARD_USER_ID'],
1331 'chatTitle' =>
$arParams[
'PARAMS'][
'FORWARD_CHAT_TITLE'],
1335 $arParams[
'PARAMS'][
'FORWARD_CONTEXT_ID'],
1338 $arParams[
'PARAMS'][
'FORWARD_CHAT_TITLE']
1343 if (isset(
$arParams[
'PARAMS'][
'REPLY_ID']))
1345 $replyIds[] = (int)
$arParams[
'PARAMS'][
'REPLY_ID'];
1349 $additionalEntitiesAdapter->addEntities(
$messages);
1350 $additionalEntitiesAdapter->setAdditionalPopupData($additionalPopupData);
1351 $additionalEntitiesRest = $additionalEntitiesAdapter->toRestFormat([
1352 'WITHOUT_OWN_REACTIONS' =>
true,
1353 'MESSAGE_ONLY_COMMON_FIELDS' =>
true,
1356 $multidialog =
null;
1357 if (isset($arChat[
'multidialogs'][
$arParams[
'CHAT_ID']]))
1359 $multidialog = $arChat[
'multidialogs'][
$arParams[
'CHAT_ID']];
1363 $multidialog = $multidialogBot;
1373 'dialogId' => isset(
$arParams[
'TO_CHAT_ID'])?
'chat'.$arParams[
'TO_CHAT_ID']: 0,
1374 'chat' => $arChat[
'chat'] ?? [],
1375 'copilot' => $copilotData ??
null,
1376 'lines' => $arChat[
'lines'][
$arParams[
'CHAT_ID']] ??
null,
1377 'multidialog' => $multidialog,
1378 'userInChat' => $arChat[
'userInChat'] ?? [],
1379 'userBlockChat' => $arChat[
'userChatBlockStatus'] ?? [],
1380 'users' => (is_array($arUsers) && is_array($arUsers[
'users'])) ? $arUsers[
'users'] :
null,
1383 'templateId' =>
$arParams[
'TEMPLATE_ID'],
1384 'templateFileId' =>
$arParams[
'FILE_TEMPLATE_ID'],
1385 'prevId' => intval(
$arParams[
'PREV_ID']),
1387 'senderId' =>
$arParams[
'FROM_USER_ID'],
1388 'recipientId' => isset(
$arParams[
'TO_CHAT_ID'])?
'chat'.$arParams[
'TO_CHAT_ID']:
$arParams[
'TO_USER_ID'],
1389 'system' =>
$arParams[
'SYSTEM'] ==
'Y'?
'Y':
'N',
1395 'importantFor' => array_values(
$arParams[
'IMPORTANT_FOR'] ?? []),
1396 'isImportant' => isset(
$arParams[
'IS_IMPORTANT']) &&
$arParams[
'IS_IMPORTANT'] ===
'Y',
1397 'additionalEntities' => $additionalEntitiesRest,
1398 'forward' => $forwardInfo,
1400 'counterType' => $chat->getCounterType()->value,
1401 'recentConfig' => $chat->getRecentConfig()->toPullFormat(),
1404 'messagesAutoDeleteConfigs' => $messagesAutoDeleteConfigs->toRestFormat(),
1408 private static function prepareCopilotData(
array $arParams,
int $chatId,
bool $isCopilotChat):
array
1410 $roleManager = (
new RoleManager())->setContextUser((
int)
$arParams[
'FROM_USER_ID']);
1414 !isset($messageRole)
1415 && \
Bitrix\
Main\Loader::includeModule(
'imbot')
1419 $messageRole = RoleManager::getDefaultRoleCode();
1425 $chat = Chat::getInstance($chatId);
1426 $engineManager =
new EngineManager();
1427 $engineCode = $chat instanceof Chat\CopilotChat ? $chat->getEngineCode() :
null;
1428 $engineName = isset($engineCode) ? $engineManager->getEngineNameByCode($engineCode) :
null;
1431 'dialogId' => \Bitrix\Im\Dialog::getDialogId($chatId),
1432 'role' => $roleManager->getMainRole($chatId),
1433 'engine' => $engineCode,
1437 isset($engineCode, $engineName)
1438 ? [[
'code' => $engineCode,
'name' => $engineName]]
1444 isset(
$arParams[
'PARAMS'][
'FORWARD_ID'])
1445 ? (int)
$arParams[
'PARAMS'][
'FORWARD_ID']
1450 'chats' => $chatData ??
null,
1451 'messages' => !empty($messageRole) ? [[
'id' =>
$messageId,
'role' => $messageRole]] :
null,
1452 'roles' => $roleManager->getRoles(
1453 $isCopilotChat ? [$roleManager->getMainRole($chatId), $messageRole] : [$messageRole]
1455 'engines' => $engineData,
1459 public static function GetChatId($fromUserId, $toUserId, $createIfNotExists =
true)
1464 $fromUserId = intval($fromUserId);
1465 $toUserId = intval($toUserId);
1467 if (intval($fromUserId) <= 0 || intval($toUserId) <= 0)
1472 if ($fromUserId == $toUserId)
1475 $chatId = $chat->GetPersonalChat($fromUserId);
1492 and C.TYPE = '".IM_MESSAGE_PRIVATE.
"'
1493 and RF.USER_ID = ".$fromUserId.
"
1494 and RT.USER_ID = ".$toUserId.
"
1497 and RF.CHAT_ID = RT.CHAT_ID
1502 $chatId = intval(
$arRes[
'CHAT_ID']);
1506 if (!$createIfNotExists)
1517 'TYPE' => Chat::IM_TYPE_PRIVATE,
1518 'FROM_USER_ID' => $fromUserId,
1519 'TO_USER_ID' => $toUserId,
1521 $chatId =
$result->getResult()[
'CHAT_ID'] ?? 0;
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getRelation($chatId, $params=[])
static hasAccess($dialogId, $userId=null)
static isUnread(int $userId, string $itemType, string $dialogId)
static parse($text, $params=Array())
static parseLegacyFormat($text, $params=Array())
static getInstance(?int $id)
static getConnection($name="")
static includeModule($moduleName)
static createFromTimestamp($timestamp)
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static GetFiles($chatId, $fileId=false, $checkPermission=true)
static GetUserOffset(array $params)
static SetLastSendId($chatId, $userId, $lastSendId)
SetReadMessage($fromUserId, $lastId=null, $byEvent=false)
static SetLastIdForUnread($chatId, $userId, $lastId)
GetUnreadMessage($arParams=Array())
GetLastSendMessage($arParams)
static SetReadMessageAll($fromUserId)
static GetFormatMessage($arParams)
GetMessage($id, $files=false)
GetLastMessage($toUserId, $fromUserId=false, $loadUserData=false, $bTimeZone=true, $limit=true)
static UpdateMessageOut($id, $messageOut)
static GetChatId($fromUserId, $toUserId, $createIfNotExists=true)
static GetUnsendMessage($order="ASC")
static SetLastId($chatId, $userId, $lastId=null)
__construct($user_id=false, $arParams=Array())
SetUnReadMessage($fromUserId, $lastId)
static Delete($id, $userId=null, $completeDelete=false, $byEvent=false)
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=[])
IsModuleInstalled($module_id)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
$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']