- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::chatGet
static function chatGet($arParams, $n, CRestServer $server)
{
global $USER;
if (!$USER->IsAuthorized())
{
throw new BitrixRestRestException("Method not available for guest session.", "AUTHORIZE_ERROR", CRestServer::STATUS_FORBIDDEN);
}
$arParams = array_change_key_case($arParams, CASE_UPPER);
if (isset($arParams['DIALOG_ID']))
{
if (!BitrixImCommon::isDialogId($arParams['DIALOG_ID']))
{
throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
if (!BitrixImDialog::hasAccess($arParams['DIALOG_ID']))
{
throw new BitrixRestRestException("You do not have access to the specified dialog", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
}
$chatId = BitrixImDialog::getChatId($arParams['DIALOG_ID']);
if (!$chatId)
{
throw new BitrixRestRestException("You don't have access to this chat", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$result = BitrixImChat::getById($chatId, ['LOAD_READED' => true, 'JSON' => true]);
if (!$result)
{
throw new BitrixRestRestException("You don't have access to this chat", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$result['dialog_id'] = $arParams['DIALOG_ID'];
return $result;
}
else if (
isset($arParams['ENTITY_TYPE']) && isset($arParams['ENTITY_ID'])
&& !empty($arParams['ENTITY_TYPE']) && !empty($arParams['ENTITY_ID'])
)
{
$chatData = BitrixImModelChatTable::getList(Array(
'select' => ['ID'],
'filter' => [
'=ENTITY_TYPE' => $arParams['ENTITY_TYPE'],
'=ENTITY_ID' => $arParams['ENTITY_ID'],
]
))->fetch();
if ($chatData)
{
return Array(
'ID' => (int)$chatData['ID']
);
}
}
return null;
}