• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::chatFavoriteAdd
static function chatFavoriteAdd($arParams, $n, CRestServer $server)
{
	$arParams = array_change_key_case($arParams, CASE_UPPER);
	if (!isset($arParams['MESSAGE_ID']) || (int)$arParams['MESSAGE_ID'] <= 0)
	{
		throw new BitrixRestRestException('MESSAGE_ID can`t be empty', 'MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
	}

	$messageId = (int)$arParams['MESSAGE_ID'];

	$message = new BitrixImV2Message($messageId);

	if ($message->getMessageId() === null)
	{
		throw new BitrixRestRestException('Message not found', BitrixImV2MessageMessageError::MESSAGE_NOT_FOUND, CRestServer::STATUS_WRONG_REQUEST);
	}

	$chat = $message->getChat();

	if (!$chat->hasAccess())
	{
		throw new BitrixRestRestException('You do not have access to this chat', BitrixImV2RestRestError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	if ($chat->getStartId() > $messageId)
	{
		throw new BitrixRestRestException('You do not have access to this message', BitrixImV2MessageMessageError::MESSAGE_ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	$markResult = $message->markAsFavorite();
	if (!$markResult->isSuccess())
	{
		$error = $markResult->getErrors()[0];
		if (isset($error))
		{
			throw new BitrixRestRestException($error->getMessage(), $error->getCode(), CRestServer::STATUS_WRONG_REQUEST);
		}
	}

	return $markResult->isSuccess();
}