- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::chatTaskPrepare
static function chatTaskPrepare($arParams, $n, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
if ($server->getAuthType() !== BitrixRestSessionAuthAuth::AUTH_TYPE && !self::isDebugEnabled())
{
throw new BitrixRestRestException('This method is available only with session auth type', 'WRONG_AUTH_TYPE', CRestServer::STATUS_WRONG_REQUEST);
}
$message = null;
$messageId = null;
if (isset($arParams['MESSAGE_ID']) && (int)$arParams['MESSAGE_ID'] > 0)
{
$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();
}
elseif (isset($arParams['CHAT_ID']) && (int)$arParams['CHAT_ID'] > 0)
{
$chatId = (int)$arParams['CHAT_ID'];
$chat = BitrixImV2Chat::getInstance($chatId);
}
else
{
throw new BitrixRestRestException('Message ID and chat ID can`t be empty together', 'CHAT_ID_MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
if (!$chat->hasAccess())
{
throw new BitrixRestRestException('You do not have access to this chat', BitrixImV2RestRestError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
}
if (isset($messageId) && $messageId < $chat->getStartId())
{
throw new BitrixRestRestException('You do not have access to this message', BitrixImV2MessageMessageError::MESSAGE_ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
}
$taskService = new BitrixImV2LinkTaskTaskService();
$result = $taskService->prepareDataForCreateSlider($chat, $message);
if (!$result->isSuccess())
{
$error = $result->getErrors()[0];
if (isset($error))
{
throw new BitrixRestRestException($error->getMessage(), $error->getCode(), CRestServer::STATUS_WRONG_REQUEST);
}
}
$data = $result->getResult();
return [
'link' => $data['LINK'],
'params' => $data['PARAMS']
];
}