- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::chatUserAdd
static function chatUserAdd($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']);
if ($arParams['CHAT_ID'] <= 0)
{
throw new BitrixRestRestException("Chat ID can't be empty", "CHAT_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
if (CIMChat::GetGeneralChatId() == $arParams['CHAT_ID'])
{
throw new BitrixRestRestException("Action unavailable", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
}
if (!Chat::isActionAllowed('chat' . $arParams['CHAT_ID'], 'EXTEND'))
{
throw new BitrixRestRestException('It is forbidden to add users to this chat', 'ACCESS_ERROR', CRestServer::STATUS_FORBIDDEN);
}
$userId = $USER->GetID();
if ($server->getMethod() == "imbot.chat.user.add")
{
$userId = self::getBotId($arParams, $server);
}
$hideHistory = null;
if (isset($arParams['HIDE_HISTORY']))
{
if ($arParams['HIDE_HISTORY'] == 'N')
{
$hideHistory = false;
}
else
{
$hideHistory = (bool)$arParams['HIDE_HISTORY'];
}
}
if (BitrixImUser::getInstance($userId)->isExtranet())
{
if (is_string($arParams['USERS']))
{
$arParams['USERS'] = CUtil::JsObjectToPhp($arParams['USERS']);
}
if (!is_array($arParams['USERS']))
{
throw new BitrixRestRestException("User IDs must be passed in array format", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
}
$arParams['USERS'] = BitrixImIntegrationSocialnetworkExtranet::filterUserList($arParams['USERS'], $userId);
}
$CIMChat = new CIMChat($userId);
$result = $CIMChat->AddUser($arParams['CHAT_ID'], $arParams['USERS'], $hideHistory);
if (!$result)
{
throw new BitrixRestRestException("You don't have access or user already member in chat", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
}
return true;
}