• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
  • Класс: BitrixImV2Chat
  • Вызов: Chat::addUsersToRelation
protected function addUsersToRelation(array $usersToAdd, array $managerIds = [], ?bool $hideHistory = null)
{
	if (empty($usersToAdd))
	{
		return;
	}

	$hideHistory ??= false;

	$managersMap = [];
	foreach ($managerIds as $managerId)
	{
		$managersMap[$managerId] = $managerId;
	}

	$relations = $this->getRelations();
	foreach ($usersToAdd as $userId)
	{
		$user = ImV2EntityUserUser::getInstance($userId);
		$hideHistory = (!static::EXTRANET_CAN_SEE_HISTORY && $user->isExtranet()) ? true : $hideHistory;
		$relation = new Relation();
		$relation
			->setChatId($this->getId())
			->setMessageType($this->getType())
			->setUserId($userId)
			->setLastId($this->getLastMessageId())
			->setStatus(IM_STATUS_READ)
			->fillRestriction($hideHistory, $this)
		;
		if (isset($managersMap[$userId]))
		{
			$relation->setManager(true);
		}
		$relations->add($relation);
	}
	$relations->save(true);
	$this->relations = [];
}