32use Bitrix\Intranet\ActionFilter\IntranetUser;
111 'setManageUsersAdd' => [
118 'setManageUsersDelete' => [
132 'setManageSettings' => [
139 'setDisappearingDuration' => [
171 new ChatTypeFilter([OpenChat::class, OpenLineChat::class, GeneralChat::class]),
174 'extendPullWatch' => [
197 function ($className, $id) {
198 return \Bitrix\Im\V2\Chat::getInstance((
int)$id);
221 $result = $this->load($chat, $user, $messageLimit, $pinLimit);
241 $result = $this->load($message->
getChat(), $user, $messageLimit, $pinLimit, $message);
256 return (
new RestAdapter($chat))->toRestFormat([
'POPUP_DATA_EXCLUDE' => [UserPopupItem::class]]);
262 public function listSharedAction(array $filter,
int $limit = self::DEFAULT_LIMIT,
int $offset = 0): ?array
264 if (!isset($filter[
'userId']))
270 $userId = (int)$filter[
'userId'];
271 $chats = \Bitrix\Im\V2\Chat::getSharedChatsWithUser($userId, $this->
getLimit($limit), $offset);
272 \Bitrix\Im\V2\Chat::fillRole($chats);
273 $result = [
'chats' => []];
275 foreach ($chats as $chat)
277 $result[
'chats'][] = $chat->toRestFormat([
'CHAT_SHORT_FORMAT' =>
true,
'CHAT_WITH_DATE_MESSAGE' =>
true]);
291 if ($chatId ===
false || $chatId === 0)
298 return [
'dialogId' =>
"chat{$chatId}"];
316 \Bitrix\Im\V2\Chat::readAllChats((
int)$user->
getId());
336 $chat->startRecordVoice();
338 return [
'result' =>
true];
346 $fields[
'type'] = $this->getValidatedType($fields[
'type'] ??
null);
349 !isset($fields[
'entityType'])
350 || $fields[
'entityType'] !==
'VIDEOCONF'
351 || !isset($fields[
'conferencePassword'])
354 unset($fields[
'conferencePassword']);
359 if (!$result->isSuccess())
375 $userId = isset($currentUser) ? $currentUser->getId() :
null;
376 $relation = $chat->getSelfRelation();
378 $changeSettings =
false;
382 if ($chat->getAuthorId() === (
int)$userId)
384 $changeSettings =
true;
387 elseif ($relation->getManager())
391 $changeSettings =
true;
409 if (isset($fields[
'entityType']))
411 $chat->setEntityType($fields[
'entityType']);
413 if (isset($fields[
'entityId']))
415 $chat->setEntityId($fields[
'entityId']);
417 if (isset($fields[
'entityData1']))
419 $chat->setEntityData1($fields[
'entityData1']);
421 if (isset($fields[
'entityData2']))
423 $chat->setEntityData2($fields[
'entityData2']);
425 if (isset($fields[
'entityData3']))
427 $chat->setEntityData3($fields[
'entityData3']);
429 if (isset($fields[
'ownerId']))
431 $chat->setAuthorId($fields[
'ownerId']);
433 if (isset($fields[
'manageUsersAdd']))
435 $chat->setManageUsersAdd($fields[
'manageUsersAdd']);
437 if (isset($fields[
'manageUsersDelete']))
439 $chat->setManageUsersDelete($fields[
'manageUsersDelete']);
441 if (isset($fields[
'manageUI']))
443 $chat->setManageUI($fields[
'manageUI']);
445 if (isset($fields[
'manageSettings']))
447 $chat->setManageSettings($fields[
'manageSettings']);
449 if (isset($fields[
'canPost']))
451 $chat->setCanPost($fields[
'canPost']);
453 if (isset($fields[
'managers']))
455 $chat->setManagers($fields[
'managers']);
461 if (isset($fields[
'title']))
463 $chat->setTitle($fields[
'title']);
465 if (isset($fields[
'description']))
467 $chat->setDescription($fields[
'description']);
469 if (isset($fields[
'color']))
471 $chat->setColor($fields[
'color']);
473 if (isset($fields[
'avatar']) && $fields[
'avatar'])
475 if (is_numeric((
string)$fields[
'avatar']))
486 $result = $chat->save();
488 if (!$result->isSuccess())
493 return $result->isSuccess();
502 $hideHistoryBool = $hideHistory ===
null ? null : $this->
convertCharToBool($hideHistory,
true);
503 $chat->addUsers($userIds, [], $hideHistoryBool);
505 return [
'result' =>
true];
515 return [
'result' =>
true];
525 $chat->extendPullWatch();
528 return [
'result' =>
true];
536 $result = $chat->deleteUser($userId);
538 if (!$result->isSuccess())
545 return [
'result' =>
true];
555 $chat->setTitle($title);
556 $result = $chat->save();
557 if (!$result->isSuccess())
562 return $result->isSuccess();
570 $chat->setDescription($description);
571 $result = $chat->save();
572 if (!$result->isSuccess())
577 return $result->isSuccess();
585 $result = $chat->validateColor();
586 if (!$result->isSuccess())
591 $chat->setColor($color);
592 $result = $chat->save();
594 if (!$result->isSuccess())
599 return $result->isSuccess();
607 $result = $chat->updateAvatarId($avatarId);
609 if (!$result->isSuccess())
614 return [
'result' =>
true];
622 $result = $chat->updateAvatar($avatarBase64);
624 if (!$result->isSuccess())
629 return [
'avatarId' => $result->getResult()];
639 $result = Message\Delete\DisappearService::disappearChat($chat, $hours);
640 if (!$result->isSuccess())
645 return $result->isSuccess();
653 $chat->setAuthorId($ownerId);
654 $result = $chat->save();
655 if (!$result->isSuccess())
660 return $result->isSuccess();
668 $chat->setManagers($userIds);
669 $result = $chat->save();
670 if (!$result->isSuccess())
675 return $result->isSuccess();
683 $chat->setManageUsersAdd($rightsLevel);
684 $result = $chat->save();
685 if (!$result->isSuccess())
690 return $result->isSuccess();
698 $chat->setManageUsersDelete($rightsLevel);
699 $result = $chat->save();
700 if (!$result->isSuccess())
705 return $result->isSuccess();
713 $chat->setManageUI($rightsLevel);
714 $result = $chat->save();
715 if (!$result->isSuccess())
720 return $result->isSuccess();
728 $chat->setManageSettings($rightsLevel);
729 $result = $chat->save();
730 if (!$result->isSuccess())
735 return $result->isSuccess();
744 $chat->setCanPost($rightsLevel);
745 $result = $chat->save();
746 if (!$result->isSuccess())
751 return $result->isSuccess();
768 return [
'result' =>
true];
778 return [
'result' =>
true];
795 return [
'result' =>
true];
798 private function load(\
Bitrix\Im\V2\
Chat $chat,
CurrentUser $user,
int $messageLimit,
int $pinLimit, ?
Message $targetMessage =
null): array
800 $messageLimit = $this->getLimit($messageLimit);
801 $pinLimit = $this->getLimit($pinLimit);
802 $messageService =
new MessageService($targetMessage ?? $chat->getLoadContextMessage());
803 $messages = $messageService->getMessageContext($messageLimit,
Message::REST_FIELDS)->getResult();
805 [
'CHAT_ID' => $chat->getChatId(),
'START_ID' => $chat->getStartId() ?: null],
809 $restAdapter =
new RestAdapter($chat, $messages, $pins);
811 $rest = $restAdapter->toRestFormat();
813 return $messageService->fillContextPaginationData($rest, $messages, $messageLimit);
816 private function getValidatedType(?
string $type): string
818 if ($type ===
'CHANNEL')
820 return \Bitrix\Im\V2\Chat::IM_TYPE_CHANNEL;
822 if ($type ===
'COPILOT')
824 return \Bitrix\Im\V2\Chat::IM_TYPE_COPILOT;
827 return \Bitrix\Im\V2\Chat::IM_TYPE_CHAT;
static getChatId($dialogId, $userId=null)
static sortPin(\Bitrix\Im\V2\Chat $chat, int $newPosition, int $userId)
static unread($dialogId, $unread, $userId=null, ?int $markedId=null)
static pin($dialogId, $pin, $userId=null)
const MAX_PINNED_CHATS_ERROR
const INVALID_PIN_POSITION
const USER_ID_EMPTY_ERROR
const MANAGE_RIGHTS_MEMBER
const MANAGE_RIGHTS_MANAGERS
toRestFormat(RestConvertible ... $entities)
convertCharToBool(string $char, bool $default=false)
loadInContextAction(Message $message, CurrentUser $user, int $messageLimit=Chat\Message::DEFAULT_LIMIT, int $pinLimit=Pin::DEFAULT_LIMIT)
addUsersAction(\Bitrix\Im\V2\Chat $chat, array $userIds, ?string $hideHistory=null)
updateAction(\Bitrix\Im\V2\Chat $chat, array $fields)
setManageUsersAddAction(\Bitrix\Im\V2\Chat $chat, string $rightsLevel)
setColorAction(\Bitrix\Im\V2\Chat $chat, string $color)
unpinAction(\Bitrix\Im\V2\Chat $chat, CurrentUser $user)
setManageUsersDeleteAction(\Bitrix\Im\V2\Chat $chat, string $rightsLevel)
setTitleAction(\Bitrix\Im\V2\Chat $chat, string $title)
getPrimaryAutoWiredParameter()
setManageSettingsAction(\Bitrix\Im\V2\Chat $chat, string $rightsLevel)
extendPullWatchAction(\Bitrix\Im\V2\Chat $chat)
readAllAction(CurrentUser $user)
joinAction(\Bitrix\Im\V2\Chat $chat)
unreadAction(\Bitrix\Im\V2\Chat $chat)
setOwnerAction(\Bitrix\Im\V2\Chat $chat, int $ownerId)
pinAction(\Bitrix\Im\V2\Chat $chat, CurrentUser $user)
listSharedAction(array $filter, int $limit=self::DEFAULT_LIMIT, int $offset=0)
setDisappearingDurationAction(\Bitrix\Im\V2\Chat $chat, int $hours)
setCanPostAction(\Bitrix\Im\V2\Chat $chat, string $rightsLevel)
shallowLoadAction(\Bitrix\Im\V2\Chat $chat)
deleteUserAction(\Bitrix\Im\V2\Chat $chat, int $userId)
setManagersAction(\Bitrix\Im\V2\Chat $chat, array $userIds)
sortPinAction(\Bitrix\Im\V2\Chat $chat, int $newPosition, CurrentUser $user)
readAction(\Bitrix\Im\V2\Chat $chat, string $onlyRecent='N')
getAction(\Bitrix\Im\V2\Chat $chat)
loadAction(\Bitrix\Im\V2\Chat $chat, CurrentUser $user, int $messageLimit=Chat\Message::DEFAULT_LIMIT, int $pinLimit=Pin::DEFAULT_LIMIT)
setAvatarAction(\Bitrix\Im\V2\Chat $chat, string $avatarBase64)
setAvatarIdAction(\Bitrix\Im\V2\Chat $chat, int $avatarId)
setDescriptionAction(\Bitrix\Im\V2\Chat $chat, string $description)
startRecordVoiceAction(\Bitrix\Im\V2\Chat $chat)
getDialogIdAction(string $externalId)
setManageUIAction(\Bitrix\Im\V2\Chat $chat, string $rightsLevel)
static find(array $filter, array $order=['ID'=> 'DESC'], ?int $limit=null, ?Context $context=null)
convertKeysToCamelCase($data)