• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/integration/ui/entityselector/chatuserprovider.php
  • Класс: BitrixImIntegrationUIEntitySelectorChatUserProvider
  • Вызов: ChatUserProvider::getChats
static function getChats(array $options = []): array
{
	$searchQueryOption = $options['searchQuery'] ?? null;
	if (!is_string($searchQueryOption))
	{
		return [];
	}

	$options['searchQuery'] = trim($searchQueryOption);
	if (
		!isset($options['searchableChatTypes'])
		|| !is_array($options['searchableChatTypes'])
		|| mb_strlen($options['searchQuery']) < FilterHelper::getMinTokenSize()
	)
	{
		return [];
	}

	$chatTypeList = [];
	foreach (static::getSearchableChatTypes() as $chatType)
	{
		if (static::shouldSearchChatType($chatType, $options))
		{
			$chatTypeList[] = $chatType;
		}
	}
	if (empty($chatTypeList))
	{
		return [];
	}

	$options['order'] ??= ['LAST_MESSAGE_ID' => 'DESC'];
	$chatIdList = static::getChatIdList($options['searchQuery'], $chatTypeList, $options['order']);
	if (empty($chatIdList))
	{
		return [];
	}

	$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'),
		))->configureJoinType(Join::TYPE_INNER)
	);

	$query->where('RELATION.USER_ID', User::getInstance()->getId());
	$query->whereIn('ID', $chatIdList);
	$query->setOrder($options['order']);
	$query->setLimit(static::MAX_CHATS_IN_SAMPLE);

	return Chat::fillCounterData($query->fetchAll());
}