• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Message/Send/MentionService.php
  • Класс: BitrixImV2MessageSendMentionService
  • Вызов: MentionService::sendMentions
public function sendMentions(Chat $chat, Message $message): void
{
	if (
		!$chat->allowMention()
		|| !$chat->getChatId()
		|| !$message->getMessage()
		|| !$message->getAuthorId()
	)
	{
		return;
	}

	$userName = $message->getAuthor()->getFullName(false);
	if (!$userName)
	{
		return;
	}

	$userGender = $message->getAuthor()->getGender() == 'F' ? 'F' : 'M';
	$chatTitle = mb_substr(htmlspecialcharsback($chat->getTitle()), 0, 32);


	$relations = [];
	foreach ($chat->getRelations() as $relation)
	{
		$relations[$relation->getUserId()] = $relation->getNotifyBlock();
	}

	$forUsers = [];
	if (preg_match_all("/[USER=([0-9]+)( REPLACE)?](.*?)[/USER]/i", $message->getMessage(), $matches))
	{
		if ($chat->getType() == Chat::IM_TYPE_OPEN)
		{
			foreach ($matches[1] as $userId)
			{
				if (!CIMSettings::GetNotifyAccess($userId, 'im', 'mention', CIMSettings::CLIENT_SITE))
				{
					continue;
				}

				if (
					!isset($relations[$userId])
					|| $relations[$userId] === true
				)
				{
					$forUsers[$userId] = $userId;
				}
			}
		}
		else
		{
			foreach ($matches[1] as $userId)
			{
				if (!CIMSettings::GetNotifyAccess($userId, 'im', 'mention', CIMSettings::CLIENT_SITE))
				{
					continue;
				}

				if (
					isset($relations[$userId])
					&& $relations[$userId] === true
				)
				{
					$forUsers[$userId] = $userId;
				}
			}
		}
	}

	foreach ($forUsers as $userId)
	{
		if ($message->getAuthorId() == $userId)
		{
			continue;
		}

		$arMessageFields = array(
			"TO_USER_ID" => $userId,
			"FROM_USER_ID" => $message->getAuthorId(),
			"NOTIFY_TYPE" => IM_NOTIFY_FROM,
			"NOTIFY_MODULE" => "im",
			"NOTIFY_EVENT" => "mention",
			"NOTIFY_TAG" => 'IM|MENTION|'.$chat->getChatId(),
			"NOTIFY_SUB_TAG" => 'IM_MESS_'.$chat->getChatId().'_'.$userId,
			"NOTIFY_MESSAGE" => $this->prepareNotifyMessage($chatTitle, $chat->getChatId(), $userGender),
			"NOTIFY_MESSAGE_OUT" => $this->prepareNotifyMail($chatTitle, $userGender),
		);
		CIMNotify::Add($arMessageFields);//todo: Replace with new sending functional

		if ($this->isPullEnable())
		{
			BitrixPullPush::add(
				$userId,
				$this->preparePushForMentionInChat(
					$this->preparePushMessage($message, $chatTitle, $userName, $userGender),
					$message,
					$chat,
					$chatTitle
				)
			);
		}
	}
}