• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
  • Класс: BitrixImV2Chat
  • Вызов: Chat::sendEventUsersAdd
protected function sendEventUsersAdd(array $usersToAdd): void
{
	if (empty($usersToAdd))
	{
		return;
	}

	foreach ($usersToAdd as $userId)
	{
		$relation = $this->getRelations()->getByUserId($userId, $this->getId());
		if ($relation === null)
		{
			continue;
		}
		if ($relation->getUser()->isBot())
		{
			IMBot::changeChatMembers($this->getId(), $userId);
			IMBot::onJoinChat('chat'.$this->getId(), [
				'CHAT_TYPE' => $this->getType(),
				'MESSAGE_TYPE' => $this->getType(),
				'BOT_ID' => $userId,
				'USER_ID' => $this->getContext()->getUserId(),
				'CHAT_ID' => $this->getId(),
				"CHAT_AUTHOR_ID" => $this->getAuthorId(),
				"CHAT_ENTITY_TYPE" => $this->getEntityType(),
				"CHAT_ENTITY_ID" => $this->getEntityId(),
				"ACCESS_HISTORY" => (int)$relation->getStartCounter() === 0,
			]);
		}
	}

	if (!empty($this->getEntityType()))
	{
		$converter = new MainEngineResponseConverter(MainEngineResponseConverter::TO_CAMEL | MainEngineResponseConverter::UC_FIRST);
		$eventCode = $converter->process($this->getEntityType());
		//$eventCode = str_replace('_', '', ucfirst(ucwords(mb_strtolower($chatEntityType), '_')));
		foreach(GetModuleEvents("im", "OnChatUserAddEntityType".$eventCode, true) as $arEvent)
		{
			ExecuteModuleEventEx($arEvent, array([
				'CHAT_ID' => $this->getId(),
				'NEW_USERS' => $usersToAdd,
			]));
		}
	}
}