21 if ($sendingConfig ===
null)
25 $this->sendingConfig = $sendingConfig;
33 $enable = \Bitrix\Main\Loader::includeModule(
'pull');
41 !$chat->allowMention()
42 || !$chat->getChatId()
50 $userName = $message->
getAuthor()->getFullName(
false);
56 $userGender = $message->
getAuthor()->getGender() ==
'F' ?
'F' :
'M';
57 $chatTitle = mb_substr(htmlspecialcharsback($chat->getTitle()), 0, 32);
61 foreach ($chat->getRelations() as $relation)
63 $relations[$relation->getUserId()] = $relation->getNotifyBlock();
67 if (preg_match_all(
"/\[USER=([0-9]+)( REPLACE)?](.*?)\[\/USER]/i", $message->
getMessage(), $matches))
71 foreach ($matches[1] as $userId)
73 if (!\CIMSettings::GetNotifyAccess($userId,
'im',
'mention', \CIMSettings::CLIENT_SITE))
79 !isset($relations[$userId])
80 || $relations[$userId] ===
true
83 $forUsers[$userId] = $userId;
89 foreach ($matches[1] as $userId)
91 if (!\CIMSettings::GetNotifyAccess($userId,
'im',
'mention', \CIMSettings::CLIENT_SITE))
97 isset($relations[$userId])
98 && $relations[$userId] ===
true
101 $forUsers[$userId] = $userId;
107 foreach ($forUsers as $userId)
114 $arMessageFields = array(
115 "TO_USER_ID" => $userId,
117 "NOTIFY_TYPE" => \IM_NOTIFY_FROM,
118 "NOTIFY_MODULE" =>
"im",
119 "NOTIFY_EVENT" =>
"mention",
120 "NOTIFY_TAG" =>
'IM|MENTION|'.$chat->getChatId(),
121 "NOTIFY_SUB_TAG" =>
'IM_MESS_'.$chat->getChatId().
'_'.$userId,
122 "NOTIFY_MESSAGE" => $this->prepareNotifyMessage($chatTitle, $chat->getChatId(), $userGender),
123 "NOTIFY_MESSAGE_OUT" => $this->prepareNotifyMail($chatTitle, $userGender),
125 \CIMNotify::Add($arMessageFields);
129 \Bitrix\Pull\Push::add(
131 $this->preparePushForMentionInChat(
132 $this->preparePushMessage($message, $chatTitle, $userName, $userGender),
143 private function preparePushForMentionInChat(
string $pushText,
Message $message,
Chat $chat,
string $chatTitle): array
145 $avatarUser = $message->
getAuthor()->getAvatar();
146 if ($avatarUser && mb_strpos($avatarUser,
'http') !== 0)
148 $avatarUser = \Bitrix\Im\Common::getPublicDomain(). $avatarUser;
151 $avatarChat = \CIMChat::GetAvatarImage($chat->getAvatarId(), 200,
false);
152 if ($avatarChat && mb_strpos($avatarChat,
'http') !== 0)
154 $avatarChat = \Bitrix\Im\Common::getPublicDomain(). $avatarChat;
158 $result[
'push'] = [];
160 $result[
'module_id'] =
'im';
161 $result[
'push'][
'params'] = [
162 'TAG' =>
'IM_CHAT_'.$chat->getChatId(),
163 'CHAT_TYPE' => $chat->
getType(),
164 'CATEGORY' =>
'ANSWER',
165 'URL' => SITE_DIR.
'mobile/ajax.php?mobile_action=im_answer',
167 'RECIPIENT_ID' =>
'chat'.$chat->getChatId()
171 $result[
'push'][
'tag'] =
'IM_CHAT_'.$chat->getChatId();
172 $result[
'push'][
'sub_tag'] =
'IM_MESS';
173 $result[
'push'][
'app_id'] =
'Bitrix24';
174 $result[
'push'][
'message'] = $pushText;
175 $result[
'push'][
'advanced_params'] = [
177 'avatarUrl' => $avatarChat ?: $avatarUser,
178 'senderName' => $chatTitle,
179 'senderMessage' => $pushText,
185 private function preparePushMessage(Message $message,
string $chatTitle,
string $userName,
string $userGender): string
189 $pushMessage = $message->getMessage();
192 if ($message->hasFiles())
194 foreach ($message->getFiles() as $file)
196 $pushFiles .=
" [".Loc::getMessage(
'IM_MESSAGE_FILE').
": ".$file->getDiskFile()->getName().
"]";
198 $pushMessage .= $pushFiles;
201 $hasAttach = mb_strpos($pushMessage,
'[ATTACH=') !==
false;
203 $pushMessage = preg_replace(
"/\[CODE\](.*?)\[\/CODE\]/si",
" [".
Loc::getMessage(
'IM_MESSAGE_CODE').
"] ", $pushMessage);
204 $pushMessage = preg_replace(
"/\[s\].*?\[\/s\]/i",
"-", $pushMessage);
205 $pushMessage = preg_replace(
"/\[[bui]\](.*?)\[\/[bui]\]/i",
"$1", $pushMessage);
206 $pushMessage = preg_replace(
"/\\[url\\](.*?)\\[\\/url\\]/i".\BX_UTF_PCRE_MODIFIER,
"$1", $pushMessage);
207 $pushMessage = preg_replace(
"/\\[url\\s*=\\s*((?:[^\\[\\]]++|\\[ (?: (?>[^\\[\\]]+) | (?:\\1) )* \\])+)\\s*\\](.*?)\\[\\/url\\]/ixs".\BX_UTF_PCRE_MODIFIER,
"$2", $pushMessage);
208 $pushMessage = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", [
'\Bitrix\Im\Text',
'modifyShortUserTag'], $pushMessage);
209 $pushMessage = preg_replace(
"/\[USER=([0-9]+)( REPLACE)?](.+?)\[\/USER]/i",
"$3", $pushMessage);
210 $pushMessage = preg_replace(
"/\[CHAT=([0-9]{1,})\](.*?)\[\/CHAT\]/i",
"$2", $pushMessage);
211 $pushMessage = preg_replace_callback(
"/\[SEND(?:=(?:.+?))?\](?:.+?)?\[\/SEND]/i", [
'\Bitrix\Im\Text',
'modifySendPut'], $pushMessage);
212 $pushMessage = preg_replace_callback(
"/\[PUT(?:=(?:.+?))?\](?:.+?)?\[\/PUT]/i", [
'\Bitrix\Im\Text',
'modifySendPut'], $pushMessage);
213 $pushMessage = preg_replace(
"/\[CALL(?:=(.+?))?\](.+?)?\[\/CALL\]/i",
"$2", $pushMessage);
214 $pushMessage = preg_replace(
"/\[PCH=([0-9]{1,})\](.*?)\[\/PCH\]/i",
"$2", $pushMessage);
215 $pushMessage = preg_replace_callback(
"/\[ICON\=([^\]]*)\]/i", [
'\Bitrix\Im\Text',
'modifyIcon'], $pushMessage);
216 $pushMessage = preg_replace(
'#\-{54}.+?\-{54}#s',
" [".
Loc::getMessage(
'IM_MESSAGE_QUOTE').
"] ", str_replace(
'#BR#',
' ', $pushMessage));
217 $pushMessage = preg_replace(
'/^(>>(.*)(\n)?)/mi',
" [".
Loc::getMessage(
'IM_MESSAGE_QUOTE').
"] ", str_replace(
'#BR#',
' ', $pushMessage));
219 if (!$pushFiles && !$hasAttach && $message->getParams()->isSet(
'ATTACH'))
221 $pushMessage .=
" [".Loc::getMessage(
'IM_MESSAGE_ATTACH').
"]";
225 Loc::getMessage(
'IM_MESSAGE_MENTION_PUSH_2_'.$userGender, [
'#USER#' => $userName,
'#TITLE#' => $chatTitle])
230 private function prepareNotifyMail(
string $chatTitle,
string $userGender): callable
233 'IM_MESSAGE_MENTION_'.$userGender,
234 [
'#TITLE#' => $chatTitle],
239 private function prepareNotifyMessage(
string $chatTitle,
int $chatId,
string $userGender): callable
242 'IM_MESSAGE_MENTION_'.$userGender,
243 [
'#TITLE#' =>
'[CHAT='.$chatId.
']'.$chatTitle.
'[/CHAT]'],
static getMessage($code, $replace=null, $language=null)