• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/chat.php
  • Класс: BitrixImChat
  • Вызов: Chat::getById
static function getById($id, $params = array())
{
	$userId = BitrixImCommon::getUserId();
	if (!$userId)
	{
		return false;
	}

	$checkAccessParam = $params['CHECK_ACCESS'] ?? null;
	$chats = self::getList(Array(
		'FILTER' => Array('ID' => $id),
		'SKIP_ACCESS_CHECK' => $checkAccessParam === 'Y'? 'N': 'Y',
 		));
	if ($chats)
	{
		$chat = $chats[0];
	}
	else
	{
		return false;
	}

	if (isset($params['LOAD_READED']) && $params['LOAD_READED'])
	{
		$userOptions = ['SKIP_ONLINE' => 'Y'];
		if ($chat['ENTITY_TYPE'] == 'LIVECHAT')
		{
			[$lineId] = explode('|', $chat['CHAT_ENTITY_ID']);
			$userOptions['LIVECHAT'] = $lineId;
			$userOptions['USER_CODE'] = 'livechat|' . $lineId . '|' . $id . '|' . $userId;
		}

		$relations = self::getRelation($id);

		$chat['READED_LIST'] = [];
		$chat['MANAGER_LIST'] = [];
		foreach ($relations as $relation)
		{
			if (
				$relation['USER_ID'] != $userId
				//&& $relation['STATUS'] == self::STATUS_READ
				&& BitrixImUser::getInstance($relation['USER_ID'])->isActive()
			)
			{
				$user = BitrixImUser::getInstance($relation['USER_ID'])->getArray($userOptions);
				$chat['READED_LIST'][] = [
					'USER_ID' => (int)$relation['USER_ID'],
					'USER_NAME' => $user['NAME'],
					'MESSAGE_ID' => (int)$relation['LAST_ID'],
					'DATE' => $relation['LAST_READ'],
				];
			}

			if ($relation['MANAGER'] === 'Y')
			{
				$chat['MANAGER_LIST'][] = (int)$relation['USER_ID'];
			}
		}

		// region v2

		$chatInstance = BitrixImV2Chat::getInstance((int)$id);
		$chat['LAST_MESSAGE_VIEWS'] = $chatInstance->getLastMessageViews();
		$chat['LAST_ID'] = (new ReadService($userId))->getLastIdByChatId((int)$id);
		$chat['MARKED_ID'] = Recent::getMarkedId($userId, $chatInstance->getType(), $chatInstance->getDialogId());

		// endregion
	}

	if ($params['JSON'] ?? null)
	{
		$chat = self::toJson($chat);
	}

	return $chat;
}