- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::chatReminderAdd
static function chatReminderAdd($arParams, $n, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
if (!isset($arParams['DATE_REMIND']))
{
throw new BitrixRestRestException('DATE_REMIND can`t be empty', BitrixImV2LinkReminderReminderError::DATE_REMIND_EMPTY, CRestServer::STATUS_FORBIDDEN);
}
$dateRemind = new DateTime($arParams['DATE_REMIND'], DateTimeInterface::RFC3339);
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);
}
$addResult = $message->addToReminder($dateRemind);
if (!$addResult->isSuccess())
{
$error = $addResult->getErrors()[0];
if (isset($error))
{
throw new BitrixRestRestException($error->getMessage(), $error->getCode(), CRestServer::STATUS_WRONG_REQUEST);
}
}
return $addResult->isSuccess();
}