28 if ($sendingConfig ===
null)
32 $this->sendingConfig = $sendingConfig;
40 $enable = \Bitrix\Main\Loader::includeModule(
'pull');
66 'command' =>
'message',
67 'params' => (
new PushFormat())->formatPrivateMessage($message, $chat),
68 'extra' => \Bitrix\Im\Common::getPullExtra(),
71 $pullMessageTo = $pullMessage;
72 $pullMessageTo[
'params'][
'dialogId'] = $fromUserId;
74 $pullMessageFrom = $pullMessage;
75 $pullMessageFrom[
'params'][
'dialogId'] = $toUserId;
77 $pullMessageFrom[
'params'][
'counter'] = $counters[$fromUserId] ?? 0;
78 \Bitrix\Pull\Event::add($fromUserId, $pullMessageFrom);
80 if ($fromUserId != $toUserId)
82 $pullMessageTo[
'params'][
'counter'] = $counters[$toUserId] ?? 0;
83 \Bitrix\Pull\Event::add($toUserId, $pullMessageTo);
85 $pullMessageTo = $this->preparePushForPrivate($pullMessageTo);
86 $pullMessageFrom = $this->preparePushForPrivate($pullMessageFrom);
88 if ($this->sendingConfig->sendPush())
93 $pullMessageTo[
'push'][
'advanced_params'][
'senderMessage'] = $message->
getPushMessage();
95 $pullMessageFrom[
'push'][
'advanced_params'][
'senderMessage'] = $message->
getPushMessage();
98 $pullMessageTo[
'push'][
'advanced_params'][
'counter'] = $counters[$toUserId] ?? 0;
99 \Bitrix\Pull\Push::add($toUserId, $pullMessageTo);
101 $pullMessageFrom[
'push'][
'advanced_params'][
'counter'] = $counters[$fromUserId] ?? 0;
102 \Bitrix\Pull\Push::add($fromUserId, array_merge_recursive($pullMessageFrom, [
'push' => [
103 'skip_users' => [$fromUserId],
104 'advanced_params' => [
105 "notificationsToCancel" => [
'IM_MESS'],
107 'send_immediately' =>
'Y',
117 private function preparePushForPrivate(array $params): array
119 $pushText = $this->prepareMessageForPush($params[
'params']);
120 unset($params[
'params'][
'message'][
'text_push']);
122 if (isset($params[
'params'][
'system']) && $params[
'params'][
'system'] ==
'Y')
129 $userName =
User::getInstance($params[
'params'][
'message'][
'senderId'])->getFullName(
false);
130 $avatarUser =
User::getInstance($params[
'params'][
'message'][
'senderId'])->getAvatar();
131 if ($avatarUser && mb_strpos($avatarUser,
'http') !== 0)
133 $avatarUser = \Bitrix\Im\Common::getPublicDomain().$avatarUser;
137 if ($params[
'params'][
'users'][$params[
'params'][
'message'][
'senderId']])
139 $params[
'params'][
'users'] = [
140 $params[
'params'][
'message'][
'senderId'] => $params[
'params'][
'users'][$params[
'params'][
'message'][
'senderId']]
145 $params[
'params'][
'users'] = [];
148 unset($params[
'extra']);
150 array_walk_recursive($params,
function(&$item, $key)
156 else if ($item instanceof DateTime)
158 $item = date(
'c', $item->getTimestamp());
163 $result[
'module_id'] =
'im';
164 $result[
'push'] = [];
165 $result[
'push'][
'type'] =
'message';
166 $result[
'push'][
'tag'] =
'IM_MESS_'.(int)$params[
'params'][
'message'][
'senderId'];
167 $result[
'push'][
'sub_tag'] =
'IM_MESS';
168 $result[
'push'][
'app_id'] =
'Bitrix24';
169 $result[
'push'][
'message'] = $pushText;
170 $result[
'push'][
'advanced_params'] = [
171 'group' =>
'im_message',
172 'avatarUrl' => $avatarUser,
173 'senderName' => $userName,
174 'senderMessage' => $pushText,
175 'data' => $this->prepareEventForPush($params[
'command'], $params[
'params']),
177 $result[
'push'][
'params'] = [
178 'TAG' =>
'IM_MESS_'.$params[
'params'][
'message'][
'senderId'],
179 'CATEGORY' =>
'ANSWER',
180 'URL' => SITE_DIR.
'mobile/ajax.php?mobile_action=im_answer',
182 'RECIPIENT_ID' => (int)$params[
'params'][
'message'][
'senderId'],
183 'MESSAGE_ID' => $params[
'params'][
'message'][
'id']
210 $skippedRelations = [];
214 foreach ($chat->getRelations() as $relation)
216 if ($this->sendingConfig->addRecent() !==
true)
218 $skippedRelations[$relation->getId()] =
true;
221 if ($relation->getUser()->getExternalAuthId() == \
Bitrix\Im\Bot::EXTERNAL_AUTH_ID)
224 elseif ($relation->getUser()->isActive() !==
true)
226 $skippedRelations[$relation->getId()] =
true;
232 if ($relation->getUser()->getExternalAuthId() ==
'imconnector')
234 $skippedRelations[$relation->getId()] =
true;
239 if ($relation->getUserId() == $fromUserId)
241 \CPushManager::DeleteFromQueueBySubTag($fromUserId,
'IM_MESS');
243 elseif ($relation->getNotifyBlock() && !$this->sendingConfig->sendPushImmediately())
245 $pushUserSkip[] = $relation->getChatId();
246 $pushUserSend[] = $relation->getChatId();
248 elseif (!$this->sendingConfig->sendPush())
253 $pushUserSend[] = $relation[
'USER_ID'];
259 'command' =>
'messageChat',
260 'params' => $this->getFormatGroupChatMessage($message, $chat),
261 'extra' => \Bitrix\Im\Common::getPullExtra()
264 foreach ($chat->getRelations() as $relation)
266 if (isset($skippedRelations[$relation->getId()]))
270 $events[$relation->getUserId()] = $pullMessage;
271 $events[$relation->getUserId()][
'params'][
'counter'] = $counters[$relation->getUserId()] ?? 0;
272 $events[$relation->getUserId()][
'groupId'] =
276 .
'_'. $events[$relation[
'USER_ID']][
'params'][
'counter']
282 $watchPullMessage = $pullMessage;
283 $watchPullMessage[
'params'][
'message'][
'params'][
'NOTIFY'] =
'N';
284 \CPullWatch::AddToStack(
'IM_PUBLIC_'. $chat->getChatId(), $watchPullMessage);
288 foreach ($groups as $group)
290 \Bitrix\Pull\Event::add($group[
'users'], $group[
'event']);
292 $userList = array_intersect($pushUserSend, $group[
'users']);
293 if (!empty($userList))
295 $pushParams = $group[
'event'];
297 $pushParams = $this->preparePushForChat($pushParams);
299 if ($this->sendingConfig->sendPushImmediately())
301 $pushParams[
'push'][
'important'] =
'Y';
304 $pushParams[
'skip_users'] = $pushUserSkip;
309 $pushParams[
'push'][
'advanced_params'][
'senderMessage'] = $message->
getPushMessage();
311 $pushParams[
'push'][
'advanced_params'][
'counter'] = $group[
'event'][
'params'][
'counter'];
313 \Bitrix\Pull\Push::add($userList, $pushParams);
323 private function getFormatGroupChatMessage(
Message $message,
GroupChat $chat): array
327 $arUsers = \CIMContactList::GetUserData(Array(
332 $arChat = \CIMChat::GetChatData([
333 'ID' => $chat->getChatId(),
339 $extraParamContext = $pushParams[
'CONTEXT'] ??
null;
341 !empty($arUsers[
'users'])
343 && \
Bitrix\Main\Loader::includeModule(
'imopenlines')
346 [$lineId, $userId] = explode(
'|', $arChat[
'chat'][$chat->getChatId()][
'entity_id']);
347 $userCode =
'livechat|' . $lineId .
'|' . $chat->getChatId() .
'|' . $userId;
348 unset($lineId, $userId);
350 foreach ($arUsers[
'users'] as $userId => $userData)
352 $arUsers[
'users'][$userId] = \Bitrix\ImOpenLines\Connector::getOperatorInfo($pushParams[
'LINE_ID'], $userId, $userCode);
357 'chatId' => $chat->getChatId(),
358 'dialogId' => $chat->getDialogId(),
359 'chat' => $arChat[
'chat'] ?? [],
360 'lines' => $arChat[
'lines'][$chat->getChatId()] ??
null,
361 'userInChat' => $arChat[
'userInChat'] ?? [],
362 'userBlockChat' => $arChat[
'userChatBlockStatus'] ?? [],
363 'users' => (is_array($arUsers) && is_array($arUsers[
'users'])) ? $arUsers[
'users'] : null,
365 'id' => $message->getMessageId(),
366 'templateId' => $message->getUuid(),
367 'templateFileId' => $message->getFileIds(),
368 'prevId' => $chat->getPrevMessageId(),
369 'chatId' => $chat->getChatId(),
370 'senderId' => $fromUserId,
371 'recipientId' => $chat->getDialogId(),
372 'system' => ($message->isSystem() ?
'Y':
'N'),
373 'date' =>
DateTime::createFromTimestamp(time()),
374 'text' =>
Text::parse($message->getMessage()),
375 'textLegacy' =>
Text::parseLegacyFormat($message->getMessage()),
376 'params' => $message->getParams()->toPullFormat(),
378 'isImportant' => $message->isImportant(),
379 'importantFor' => $message->getImportantFor(),
381 'files' => $message->getFilesDiskData(),
394 foreach ($events as $userId => $event)
396 $eventCode = $event[
'groupId'];
397 if (!isset($groups[$eventCode]))
399 $groups[$eventCode][
'event'] = $event;
401 $groups[$eventCode][
'users'][] = $userId;
402 $groups[$eventCode][
'count'] = count($groups[$eventCode][
'users']);
405 \Bitrix\Main\Type\Collection::sortByColumn($groups, [
'count' => \SORT_DESC]);
409 foreach ($groups as $eventCode => $event)
411 if ($count >= $maxUserInGroup)
413 if (isset($finalGroup[
'other']))
415 $finalGroup[
'other'][
'users'] = array_unique(array_merge($finalGroup[
'other'][
'users'], $event[
'users']));
419 $finalGroup[
'other'] = $event;
420 $finalGroup[
'other'][
'event'][
'params'][
'counter'] = 100;
425 $finalGroup[$eventCode] = $event;
430 \Bitrix\Main\Type\Collection::sortByColumn($finalGroup, [
'count' => \SORT_ASC]);
439 private function preparePushForChat(array $params): array
441 $pushText = $this->prepareMessageForPush($params[
'params']);
442 unset($params[
'params'][
'message'][
'text_push']);
444 $chatTitle = mb_substr(htmlspecialcharsback($params[
'params'][
'chat'][$params[
'params'][
'chatId']][
'name']), 0, 32);
445 $chatType = $params[
'params'][
'chat'][$params[
'params'][
'chatId']][
'type'];
446 $chatAvatar = $params[
'params'][
'chat'][$params[
'params'][
'chatId']][
'avatar'];
447 $chatTypeLetter = $params[
'params'][
'chat'][$params[
'params'][
'chatId']][
'message_type'];
450 if (($params[
'params'][
'system'] ??
null) ===
'Y' || $params[
'params'][
'message'][
'senderId'] <= 0)
457 $userName =
User::getInstance($params[
'params'][
'message'][
'senderId'])->getFullName(
false);
458 $avatarUser =
User::getInstance($params[
'params'][
'message'][
'senderId'])->getAvatar();
459 if ($avatarUser && mb_strpos($avatarUser,
'http') !== 0)
461 $avatarUser = \Bitrix\Im\Common::getPublicDomain().$avatarUser;
467 $params[
'params'][
'message'][
'senderId'],
468 $params[
'params'][
'users'][$params[
'params'][
'message'][
'senderId']]
470 && $params[
'params'][
'users'][$params[
'params'][
'message'][
'senderId']]
473 $params[
'params'][
'users'] = [
474 $params[
'params'][
'message'][
'senderId'] => $params[
'params'][
'users'][$params[
'params'][
'message'][
'senderId']]
479 $params[
'params'][
'users'] = [];
482 if ($chatAvatar ==
'/bitrix/js/im/images/blank.gif')
486 else if ($chatAvatar && mb_strpos($chatAvatar,
'http') !== 0)
488 $chatAvatar = \Bitrix\Im\Common::getPublicDomain().$chatAvatar;
491 unset($params[
'extra']);
493 array_walk_recursive($params,
function(&$item, $key)
499 else if ($item instanceof DateTime)
501 $item = date(
'c', $item->getTimestamp());
506 $result[
'module_id'] =
'im';
507 $result[
'push'][
'type'] = ($chatType ===
'open'?
'openChat': $chatType);
508 $result[
'push'][
'tag'] =
'IM_CHAT_'.intval($params[
'params'][
'chatId']);
509 $result[
'push'][
'sub_tag'] =
'IM_MESS';
510 $result[
'push'][
'app_id'] =
'Bitrix24';
511 $result[
'push'][
'message'] = ($userName? $userName.
': ':
'').$pushText;
512 $result[
'push'][
'advanced_params'] = [
513 'group' => $chatType ==
'lines'?
'im_lines_message':
'im_message',
514 'avatarUrl' => $chatAvatar? $chatAvatar: $avatarUser,
515 'senderName' => $chatTitle,
516 'senderMessage' => ($userName? $userName.
': ':
'').$pushText,
517 'senderCut' => mb_strlen($userName? $userName.
': ' :
''),
518 'data' => $this->prepareEventForPush($params[
'command'], $params[
'params'])
520 $result[
'push'][
'params'] = [
521 'TAG' =>
'IM_CHAT_'.$params[
'params'][
'chatId'],
522 'CHAT_TYPE' => $chatTypeLetter? $chatTypeLetter:
'C',
523 'CATEGORY' =>
'ANSWER',
524 'URL' => SITE_DIR.
'mobile/ajax.php?mobile_action=im_answer',
526 'RECIPIENT_ID' =>
'chat'.$params[
'params'][
'chatId'],
527 'MESSAGE_ID' => $params[
'params'][
'message'][
'id']
547 $toUserId = $chat->getAuthorId();
549 $pullNotificationParams = $this->getFormatNotify($message, $counter);
552 $needPush = \CIMSettings::GetNotifyAccess(
556 \CIMSettings::CLIENT_PUSH
564 if (isset($pushParams[
'ADVANCED_PARAMS']))
566 $advancedParams = $pushParams[
'ADVANCED_PARAMS'];
567 unset($pushParams[
'ADVANCED_PARAMS']);
571 $advancedParams = $this->prepareAdvancedParamsForNotificationPush(
572 $pullNotificationParams,
577 \Bitrix\Pull\Push::add(
584 'params' => $message->
getPushParams() ?? [
'TAG' =>
'IM_NOTIFY'],
585 'advanced_params' => $advancedParams,
586 'important' => ($this->sendingConfig->sendPushImmediately() ?
'Y':
'N'),
596 if ($sendNotifyFlash)
598 \Bitrix\Pull\Event::add(
602 'command' =>
'notifyAdd',
603 'params' => $pullNotificationParams,
617 $toUserId = $chat->getAuthorId();
619 $pullNotificationParams = $this->getFormatNotify($message, $counter);
621 \Bitrix\Pull\Event::add(
625 'command' =>
'notifyAdd',
626 'params' => $pullNotificationParams,
637 private function getFormatNotify(
Message $message,
int $counter = 0): array
643 'LINK_TARGET_SELF' =>
'Y',
657 'text' => $messageText,
659 'originalTag' => $message->getNotifyTag(),
660 'original_tag' => $message->getNotifyTag(),
661 'read' => $message->isNotifyRead() !== null ? ($message->isNotifyRead() ?
'Y' :
'N') : null,
662 'settingName' => $message->getNotifyModule().
'|'. $message->getNotifyEvent(),
663 'params' => $message->getParams()->toPullFormat(),
664 'counter' => $counter,
669 'userAvatar' => null,
674 $notify[
'users'][] = $message->
getAuthor()->getArray([
680 $notify[
'userName'] = $message->
getAuthor()->getName();
681 $notify[
'userColor'] = $message->
getAuthor()->getColor();
682 $notify[
'userAvatar'] = $message->
getAuthor()->getAvatar();
683 $notify[
'userLink'] = $message->
getAuthor()->getProfile();
693 $notify[
'title'] = htmlspecialcharsbx($message->
getNotifyTitle());
704 private function prepareAdvancedParamsForNotificationPush(array $params, ?
string $pushMessage =
null): array
706 if ($params[
'date'] instanceof DateTime)
708 $params[
'date'] = date(
'c', $params[
'date']->getTimestamp());
711 $params[
'text'] = $this->prepareMessageForPush([
'message' => [
'text' => $params[
'text']]]);
715 'group' =>
'im_notify',
716 'data' => $this->prepareNotificationEventForPush($params, $pushMessage)
719 if (isset($params[
'userName']))
721 $advancedParams[
'senderName'] = $params[
'userName'];
722 if (isset($params[
'userAvatar']))
724 $advancedParams[
'avatarUrl'] = $params[
'userAvatar'];
726 $advancedParams[
'senderMessage'] = $pushMessage ?: $params[
'text'];
729 return $advancedParams;
741 private function prepareNotificationEventForPush(array $event, ?
string $pushMessage =
null): array
744 'cmd' =>
'notifyAdd',
745 'id' => (int)$event[
'id'],
746 'type' => (
int)$event[
'type'],
747 'date' => (string)$event[
'date'],
748 'tag' => (
string)$event[
'tag'],
749 'onlyFlash' => $event[
'onlyFlash'],
750 'originalTag' => (string)$event[
'originalTag'],
751 'settingName' => (
string)$event[
'settingName'],
752 'counter' => (int)$event[
'counter'],
753 'userId' => (
int)$event[
'userId'],
754 'userName' => (string)$event[
'userName'],
755 'userColor' => (
string)$event[
'userColor'],
756 'userAvatar' => (string)$event[
'userAvatar'],
757 'userLink' => (
string)$event[
'userLink'],
758 'params' => $event[
'params'],
760 if (isset($event[
'buttons']))
762 $result[
'buttons'] = $event[
'buttons'];
767 if (isset($pushMessage))
769 $result[
'text'] = $event[
'text'];
791 return $this->changeKeysPushEvent($result, $fieldToIndex);
804 private function prepareMessageForPush(array $message): string
808 $messageText = $message[
'message'][
'text'];
809 if (isset($message[
'message'][
'text_push']) && $message[
'message'][
'text_push'])
811 $messageText = $message[
'message'][
'text_push'];
815 if (isset($message[
'message'][
'params'][
'ATTACH']) && count($message[
'message'][
'params'][
'ATTACH']) > 0)
817 $attachText = $message[
'message'][
'params'][
'ATTACH'][0][
'DESCRIPTION'];
824 (empty($messageText)?
'':
' ')
829 if (isset($message[
'files']) && count($message[
'files']) > 0)
831 $file = array_values($message[
'files'])[0];
833 if ($file[
'type'] ===
'image')
837 else if ($file[
'type'] ===
'audio')
841 else if ($file[
'type'] ===
'video')
850 $messageText .= trim($fileName);
857 $messageText = str_replace(
"\n",
' ', $messageText);
858 $messageText = preg_replace(
"/\[CODE\](.*?)\[\/CODE\]/si",
' '.$codeIcon.
' ', $messageText);
859 $messageText = preg_replace(
"/\[s\].*?\[\/s\]/i",
'-', $messageText);
860 $messageText = preg_replace(
"/\[[bui]\](.*?)\[\/[bui]\]/i",
"$1", $messageText);
861 $messageText = preg_replace(
"/\\[url\\](.*?)\\[\\/url\\]/i".\BX_UTF_PCRE_MODIFIER,
"$1", $messageText);
862 $messageText = preg_replace(
"/\\[url\\s*=\\s*((?:[^\\[\\]]++|\\[ (?: (?>[^\\[\\]]+) | (?:\\1) )* \\])+)\\s*\\](.*?)\\[\\/url\\]/ixs".\BX_UTF_PCRE_MODIFIER,
"$2", $messageText);
863 $messageText = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", [
'\Bitrix\Im\Text',
'modifyShortUserTag'], $messageText);
864 $messageText = preg_replace(
"/\[USER=([0-9]+)( REPLACE)?](.+?)\[\/USER]/i",
"$3", $messageText);
865 $messageText = preg_replace(
"/\[CHAT=([0-9]{1,})\](.*?)\[\/CHAT\]/i",
"$2", $messageText);
866 $messageText = preg_replace_callback(
"/\[SEND(?:=(?:.+?))?\](?:.+?)?\[\/SEND]/i", [
'\Bitrix\Im\Text',
"modifySendPut"], $messageText);
867 $messageText = preg_replace_callback(
"/\[PUT(?:=(?:.+?))?\](?:.+?)?\[\/PUT]/i", [
'\Bitrix\Im\Text',
"modifySendPut"], $messageText);
868 $messageText = preg_replace(
"/\[CALL(?:=(.+?))?\](.+?)?\[\/CALL\]/i",
"$2", $messageText);
869 $messageText = preg_replace(
"/\[PCH=([0-9]{1,})\](.*?)\[\/PCH\]/i",
"$2", $messageText);
870 $messageText = preg_replace_callback(
"/\[ICON\=([^\]]*)\]/i", [
'\Bitrix\Im\Text',
'modifyIcon'], $messageText);
871 $messageText = preg_replace(
'#\-{54}.+?\-{54}#s',
' '.$quoteIcon.
' ', str_replace(
'#BR#',
' ', $messageText));
872 $messageText = preg_replace(
'/^(>>(.*)(\n)?)/mi',
' '.$quoteIcon.
' ', str_replace(
'#BR#',
' ', $messageText));
873 $messageText = preg_replace(
"/\\[color\\s*=\\s*([^\\]]+)\\](.*?)\\[\\/color\\]/is".\BX_UTF_PCRE_MODIFIER,
"$2", $messageText);
874 $messageText = preg_replace(
"/\\[size\\s*=\\s*([^\\]]+)\\](.*?)\\[\\/size\\]/is".\BX_UTF_PCRE_MODIFIER,
"$2", $messageText);
876 return trim($messageText);
879 private function prepareEventForPush(
string $command, array $event): array
883 'chatId' => (int)$event[
'chatId'],
884 'dialogId' => (
string)$event[
'dialogId'],
885 'counter' => (int)$event[
'counter'],
888 if ($event[
'notify'] !==
true)
890 $result[
'notify'] = $event[
'notify'];
893 if (!empty($event[
'chat'][$event[
'chatId']]))
895 $eventChat = $event[
'chat'][$event[
'chatId']];
898 'id' => (int)$eventChat[
'id'],
899 'name' => (
string)$eventChat[
'name'],
900 'owner' => (int)$eventChat[
'owner'],
901 'color' => (
string)$eventChat[
'color'],
902 'type' => (string)$eventChat[
'type'],
903 'date_create' => (
string)$eventChat[
'date_create'],
907 !empty($eventChat[
'avatar'])
908 && $eventChat[
'avatar'] !==
'/bitrix/js/im/images/blank.gif'
911 $chat[
'avatar'] = $eventChat[
'avatar'];
913 if ($eventChat[
'call'])
915 $chat[
'call'] = (string)$eventChat[
'call'];
917 if ($eventChat[
'call_number'])
919 $chat[
'call_number'] = (string)$eventChat[
'call_number'];
921 if ($eventChat[
'entity_data_1'])
923 $chat[
'entity_data_1'] = (string)$eventChat[
'entity_data_1'];
925 if ($eventChat[
'entity_data_2'])
927 $chat[
'entity_data_2'] = (string)$eventChat[
'entity_data_2'];
929 if ($eventChat[
'entity_data_3'])
931 $chat[
'entity_data_3'] = (string)$eventChat[
'entity_data_3'];
933 if ($eventChat[
'entity_id'])
935 $chat[
'entity_id'] = (string)$eventChat[
'entity_id'];
937 if ($eventChat[
'entity_type'])
939 $chat[
'entity_type'] = (string)$eventChat[
'entity_type'];
941 if ($eventChat[
'extranet'])
943 $chat[
'extranet'] =
true;
946 $result[
'chat'] = $chat;
949 if (!empty($event[
'lines']))
951 $result[
'lines'] = $event[
'lines'];
954 if (!empty($event[
'users'][$event[
'message'][
'senderId']]))
956 $eventUser = $event[
'users'][$event[
'message'][
'senderId']];
959 'id' => (int)$eventUser[
'id'],
960 'name' => (
string)$eventUser[
'name'],
961 'first_name' => (string)$eventUser[
'first_name'],
962 'last_name' => (
string)$eventUser[
'last_name'],
963 'color' => (string)$eventUser[
'color'],
967 !empty($eventUser[
'avatar'])
968 && $eventUser[
'avatar'] !==
'/bitrix/js/im/images/blank.gif'
971 $user[
'avatar'] = (string)$eventUser[
'avatar'];
974 if ($eventUser[
'absent'])
976 $user[
'absent'] =
true;
978 if (!$eventUser[
'active'])
980 $user[
'active'] = $eventUser[
'active'];
982 if ($eventUser[
'bot'])
986 if ($eventUser[
'extranet'])
988 $user[
'extranet'] =
true;
990 if ($eventUser[
'network'])
992 $user[
'network'] =
true;
994 if ($eventUser[
'birthday'])
996 $user[
'birthday'] = $eventUser[
'birthday'];
998 if ($eventUser[
'connector'])
1000 $user[
'connector'] =
true;
1002 if ($eventUser[
'external_auth_id'] !==
'default')
1004 $user[
'external_auth_id'] = $eventUser[
'external_auth_id'];
1006 if ($eventUser[
'gender'] ===
'F')
1008 $user[
'gender'] =
'F';
1010 if ($eventUser[
'work_position'])
1012 $user[
'work_position'] = (string)$eventUser[
'work_position'];
1015 $result[
'users'] = $user;
1018 if (!empty($event[
'files']))
1020 foreach ($event[
'files'] as $key => $value)
1023 'id' => (int)$value[
'id'],
1024 'extension' => (
string)$value[
'extension'],
1025 'name' => (string)$value[
'name'],
1026 'size' => (
int)$value[
'size'],
1027 'type' => (string)$value[
'type'],
1028 'image' => $value[
'image'],
1029 'urlDownload' =>
'',
1030 'urlPreview' => (
new \
Bitrix\Main\Web\Uri($value[
'urlPreview']))->deleteParams([
'fileName'])->getUri(),
1033 if ($value[
'image'])
1035 $file[
'image'] = $value[
'image'];
1037 if ($value[
'progress'] !== 100)
1039 $file[
'progress'] = (int)$value[
'progress'];
1041 if ($value[
'status'] !==
'done')
1043 $file[
'status'] = $value[
'status'];
1046 $result[
'files'][$key] = $file;
1050 if (!empty($event[
'message']))
1052 $eventMessage = $event[
'message'];
1055 'id' => (int)$eventMessage[
'id'],
1056 'date' => (
string)$eventMessage[
'date'],
1057 'params' => $eventMessage[
'params'],
1058 'prevId' => (int)$eventMessage[
'prevId'],
1059 'senderId' => (
int)$eventMessage[
'senderId'],
1062 if (isset($message[
'params'][
'ATTACH']))
1064 unset($message[
'params'][
'ATTACH']);
1067 if ($eventMessage[
'system'] ===
'Y')
1069 $message[
'system'] =
'Y';
1072 $result[
'message'] = $message;
1090 'date_create' => 20,
1093 'entity_type' => 24,
1094 'entity_data_1' => 203,
1095 'entity_data_2' => 204,
1096 'entity_data_3' => 205,
1098 'call_number' => 202,
1099 'manager_list' => 209,
1105 'work_position' => 43,
1110 'external_auth_id' => 404,
1126 'urlDownload' => 85,
1133 return $this->changeKeysPushEvent($result, $indexToNameMap);
1136 private function changeKeysPushEvent(array $object, array $map): array
1140 foreach($object as $key => $value)
1142 $index = isset($map[$key]) ? $map[$key] : $key;
1143 if (is_null($value))
1147 if (is_array($value))
1149 $result[$index] = $this->changeKeysPushEvent($value, $map);
1153 $result[$index] = $value;