- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::chatSetOwner
static function chatSetOwner($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']);
$arParams['USER_ID'] = intval($arParams['USER_ID']);
if ($arParams['CHAT_ID'] <= 0)
{
throw new BitrixRestRestException("Chat ID can't be empty", "CHAT_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
if ($arParams['USER_ID'] <= 0)
{
throw new BitrixRestRestException("User ID can't be empty", "USER_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
$userId = $USER->GetId();
if ($server->getMethod() == mb_strtolower("imbot.chat.setOwner"))
{
$userId = self::getBotId($arParams, $server);
}
if (CIMChat::GetGeneralChatId() == $arParams['CHAT_ID'])
{
throw new BitrixRestRestException("Action unavailable", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
}
$chat = new CIMChat($userId);
$result = $chat->SetOwner($arParams['CHAT_ID'], $arParams['USER_ID']);
if (!$result)
{
throw new BitrixRestRestException("Change owner can only owner and user must be member in chat", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
}
return true;
}