• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/chat.php
  • Класс: BitrixImChat
  • Вызов: Chat::isActionAllowed
static function isActionAllowed($dialogId, $action, $entityType = null): bool
{
	if (!BitrixImCommon::isChatId($dialogId))
	{
		return true;
	}

	$chatOptions = CIMChat::GetChatOptions();
	$isAllowedByDefault = (bool)($chatOptions['DEFAULT'][$action] ?? true);

	if ($entityType && $chatOptions[$entityType])
	{
		return (bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
	}

	if ($entityType)
	{
		return $isAllowedByDefault;
	}

	$chatId = BitrixImDialog::getChatId($dialogId);
	if (!$chatId)
	{
		return $isAllowedByDefault;
	}

	$generalChatId = (int)CIMChat::GetGeneralChatId();
	if ($chatId === $generalChatId)
	{
		return (bool)($chatOptions['GENERAL'][$action] ?? $isAllowedByDefault);
	}

	$chat = BitrixImModelChatTable::getList([
		'select' => [
			'ID',
			'ENTITY_TYPE',
		],
		'filter' => [
			'ID' => $chatId,
		]
	])->fetch();

	$entityType = ($chat && $chat['ENTITY_TYPE']) ? $chat['ENTITY_TYPE'] : null;

	if ($entityType && $chatOptions[$entityType])
	{
		return (bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
	}

	return $isAllowedByDefault;
}