• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
  • Класс: BitrixImV2Chat
  • Вызов: Chat::readMessages
public function readMessages(?MessageCollection $messages, bool $byEvent = false): Result
{
	$result = new Result();

	if (isset($messages))
	{
		$messages = $messages->filterByChatId($this->chatId);

		if ($messages->count() === 0)
		{
			return $result->addError(new MessageError(MessageError::MESSAGE_NOT_FOUND));
		}
	}

	$readService = $this->getReadService();
	$startId = $readService->getLastIdByChatId($this->chatId);
	$counter = 0;

	if (isset($messages))
	{
		$counter = $readService->read($messages, $this)->getResult()['COUNTER'];
	}
	else
	{
		$counter = $readService->readAllInChat($this->chatId)->getResult()['COUNTER'];
	}

	$lastId = $readService->getLastIdByChatId($this->chatId);

	$messages ??= new MessageCollection();

	$notOwnMessages = new MessageCollection();

	foreach ($messages as $message)
	{
		if ($message->getAuthorId() !== $this->getContext()->getUserId())
		{
			$notOwnMessages->add($message);
		}
	}

	if (MainLoader::includeModule('pull'))
	{
		CIMNotify::DeleteBySubTag("IM_MESS_{$this->getChatId()}_{$this->getContext()->getUserId()}", false, false);
		CPushManager::DeleteFromQueueBySubTag($this->getContext()->getUserId(), 'IM_MESS');
		$this->sendPushRead($notOwnMessages, $lastId, $counter);
	}

	$this->sendEventRead($startId, $lastId, $counter, $byEvent);

	return $result->setResult([
		'CHAT_ID' => $this->chatId,
		'LAST_ID' => $lastId,
		'COUNTER' => $counter,
		'VIEWED_MESSAGES' => $notOwnMessages->getIds(),
	]);
}