• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/integration/ui/entityselector/chatprovider.php
  • Класс: BitrixImIntegrationUIEntitySelectorChatProvider
  • Вызов: ChatProvider::getChatsByIds
static function getChatsByIds(array $options = []): array
{
	if (empty($options['chatIds']))
	{
		return [];
	}

	$currentUserId = User::getInstance()->getId();

	$query = ChatTable::query();
	$query
		->addSelect('*')
		->addSelect('RELATION.USER_ID', 'RELATION_USER_ID')
		->addSelect('RELATION.NOTIFY_BLOCK', 'RELATION_NOTIFY_BLOCK')
		//->addSelect('RELATION.COUNTER', 'RELATION_COUNTER')
		->addSelect('RELATION.START_COUNTER', 'RELATION_START_COUNTER')
		//->addSelect('RELATION.LAST_ID', 'RELATION_LAST_ID')
		//->addSelect('RELATION.STATUS', 'RELATION_STATUS')
		//->addSelect('RELATION.UNREAD_ID', 'RELATION_UNREAD_ID')
		->addSelect('ALIAS.ALIAS', 'ALIAS_NAME')
	;

	$query->registerRuntimeField(
		'RELATION',
		new Reference(
			'RELATION',
			RelationTable::class,
			Join::on('this.ID', 'ref.CHAT_ID')
				->where('ref.USER_ID', $currentUserId),
		)
	);
	$query->whereIn('ID', $options['chatIds']);
	$query->where(Query::filter()
		->logic('or')
		->where(Query::filter()
			->logic('and')
			->where('TYPE','O')
			->where('USER_COUNT', '>', 0)
		)
		->where('RELATION.USER_ID', $currentUserId)
	);

	if (isset($options['order']) && is_array($options['order']))
	{
		$query->setOrder($options['order']);
	}
	else
	{
		$query->setOrder(['LAST_MESSAGE_ID' => 'DESC']);
	}

	if (isset($options['limit']))
	{
		$query->setLimit($options['limit']);
	}

	$chatsRaw = $query->exec()->fetchAll();

	return Chat::fillCounterData($chatsRaw);
}