• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::chatUpdateColor
static function chatUpdateColor($arParams, $n, CRestServer $server)
{
	global $USER;

	$arParams = array_change_key_case($arParams, CASE_UPPER);

	if (isset($arParams['DIALOG_ID']))
	{
		if (BitrixImCommon::isChatId($arParams['DIALOG_ID']))
		{
			$arParams['CHAT_ID'] = BitrixImDialog::getChatId($arParams['DIALOG_ID']);
		}
		else
		{
			throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
		}
	}

	$arParams['CHAT_ID'] = intval($arParams['CHAT_ID']);

	if ($arParams['CHAT_ID'] <= 0)
	{
		throw new BitrixRestRestException("Chat ID can't be empty", "CHAT_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}

	$userId = $USER->GetId();
	if (CIMChat::GetGeneralChatId() == $arParams['CHAT_ID'] && !CIMChat::CanSendMessageToGeneralChat($userId))
	{
		throw new BitrixRestRestException("Action unavailable", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
	}

	if (!BitrixImColor::isSafeColor($arParams['COLOR']))
	{
		throw new BitrixRestRestException("This color currently unavailable", "WRONG_COLOR", CRestServer::STATUS_WRONG_REQUEST);
	}

	$userId = $USER->GetId();
	if ($server->getMethod() == mb_strtolower("imbot.chat.updateColor"))
	{
		$userId = self::getBotId($arParams, $server);
	}

	$chat = new CIMChat($userId);
	$result = $chat->SetColor($arParams['CHAT_ID'], $arParams['COLOR']);

	if (!$result)
	{
		throw new BitrixRestRestException("This color currently set or chat isn't exists", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
	}

	return true;
}