19 parent::getDefaultPreFilters(),
21 new \
Bitrix\Rest\Engine\ActionFilter\Scope(
'im.import'),
22 new \
Bitrix\Main\Engine\ActionFilter\Scope(\
Bitrix\Main\Engine\ActionFilter\Scope::REST),
23 new \
Bitrix\Rest\Engine\ActionFilter\AuthType(\
Bitrix\Rest\Engine\ActionFilter\AuthType::APPLICATION)
36 $isOpen = ($fields[
'isOpen'] ??
'N') ===
'Y';
37 $type = $isOpen ? \IM_MESSAGE_OPEN : \IM_MESSAGE_CHAT;
40 'TITLE' => $fields[
'title'] ??
null,
41 'DESCRIPTION' => $fields[
'description'] ??
null,
43 'AVATAR_ID' => $this->saveAvatar($fields[
'avatar'] ??
null),
44 'ENTITY_ID' => $externalId,
45 'AUTHOR_ID' => $ownerId,
51 if (!$initResult->isSuccess())
53 $this->
addErrors($initResult->getErrors());
69 if (count($users) !== 2)
76 $users = array_map(
'intval', $users);
79 'TYPE' => \IM_MESSAGE_PRIVATE,
80 'ENTITY_ID' => $externalId,
81 'ENTITY_DATA_1' =>
"{$users[0]}|{$users[1]}",
82 'AUTHOR_ID' => $users[0],
88 if (!$initResult->isSuccess())
90 $this->
addErrors($initResult->getErrors());
115 $folderId = \CIMDisk::GetFolderModel($chatId)->getId();
116 \CIMDisk::ChangeFolderMembers($chatId, (
int)$user->
getId());
118 return [
'chatFolderId' => $folderId];
133 if (!$importService->hasAccess())
140 $abortResult = $importService->abort();
142 if (!$abortResult->isSuccess())
144 $this->
addErrors($abortResult->getErrors());
166 if (!$importService->hasAccess())
173 $finalizeResult = $importService->commitGroup($users, $server->getClientId());
175 if (!$finalizeResult->isSuccess())
177 $this->
addErrors($finalizeResult->getErrors());
199 if (!$importService->hasAccess())
206 $finalizeResult = $importService->commitPrivate($newIsMain ===
'Y', $hideOriginal ===
'Y', $server->getClientId());
208 if (!$finalizeResult->isSuccess())
210 $this->
addErrors($finalizeResult->getErrors());
220 private function saveAvatar(?
string $fileContent): ?int
222 if (!isset($fileContent) || !$fileContent)
227 $file = CRestUtil::saveFile($fileContent);
228 $imageCheck = (new \Bitrix\Main\File\Image($file[
"tmp_name"]))->getInfo();
231 || !$imageCheck->getWidth()
232 || $imageCheck->getWidth() > 5000
233 || !$imageCheck->getHeight()
234 || $imageCheck->getHeight() > 5000
240 if (!$file || !(mb_strpos($file[
'type'],
'image/') === 0))
245 return CFile::saveFile($file,
'im');
commitPrivateAction(int $chatId, string $newIsMain, CurrentUser $user, \CRestServer $server, string $hideOriginal='Y')
createGroupAction(int $ownerId, CurrentUser $user, array $fields=[], string $externalId='')
getFolderIdAction(int $chatId, CurrentUser $user)
commitGroupAction(int $chatId, array $users, CurrentUser $user, \CRestServer $server)
abortAction(int $chatId, CurrentUser $user)
createPrivateAction(array $users, CurrentUser $user, string $externalId='')
const PRIVATE_CHAT_COUNT_USERS_ERROR
static create(array $chatData)
static isAdmin(int $userId)
convertKeysToCamelCase($data)