Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
OpenChat.php
1<?php
2
3namespace Bitrix\Im\V2\Chat;
4
10
11class OpenChat extends GroupChat
12{
13 protected function getDefaultType(): string
14 {
15 return self::IM_TYPE_OPEN;
16 }
17
18 protected function checkAccessWithoutCaching(int $userId): bool
19 {
20 if (User::getInstance($userId)->isExtranet())
21 {
22 $relation = $this->withContextUser($userId)->getSelfRelation();
23
24 return $relation !== null;
25 }
26
27 return true;
28 }
29
30 protected function getAccessCodesForDiskFolder(): array
31 {
32 $accessCodes = parent::getAccessCodesForDiskFolder();
33 $departmentCode = \CIMDisk::GetTopDepartmentCode();
34
35 if ($departmentCode)
36 {
37 $driver = \Bitrix\Disk\Driver::getInstance();
38 $rightsManager = $driver->getRightsManager();
39 $accessCodes[] = [
40 'ACCESS_CODE' => $departmentCode,
41 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_READ)
42 ];
43 }
44
45 return $accessCodes;
46 }
47
48 public function startRecordVoice(): void
49 {
50 if (!Loader::includeModule('pull'))
51 {
52 return;
53 }
54
55 parent::startRecordVoice();
56 $pushFormatter = new PushFormat();
57 \CPullWatch::AddToStack('IM_PUBLIC_'.$this->getId(), $pushFormatter->formatStartRecordVoice($this));
58 }
59
60 public function sendPushUpdateMessage(Message $message): void
61 {
62 parent::sendPushUpdateMessage($message);
63 $pushFormat = new Message\PushFormat();
64 $push = $pushFormat->formatMessageUpdate($message);
65 $push['params']['dialogId'] = $this->getDialogId();
66 \CPullWatch::AddToStack('IM_PUBLIC_' . $message->getChatId(), $push);
67 }
68
69 public function getLoadContextMessage(): Message
70 {
71 $startMessageId = 0;
72
73 if ($this->getSelfRelation() === null)
74 {
75 $startMessageId = $this->getLastMessageId();
76 }
77 else
78 {
79 $startMessageId = $this->getMarkedId() ?: $this->getLastId();
80 }
81
82 return (new \Bitrix\Im\V2\Message($startMessageId))->setChatId($this->getId())->setMessageId($startMessageId);
83 }
84
85 public function extendPullWatch(): void
86 {
87 if (Loader::includeModule('pull'))
88 {
89 \CPullWatch::Add($this->getContext()->getUserId(), "IM_PUBLIC_{$this->getId()}", true);
90 }
91 }
92
93 protected function updateStateAfterUsersAdd(array $usersToAdd): self
94 {
95 parent::updateStateAfterUsersAdd($usersToAdd);
96
97 if (Loader::includeModule('pull'))
98 {
99 foreach ($usersToAdd as $userId)
100 {
101 \CPullWatch::Delete($userId, 'IM_PUBLIC_' . $this->getId());
102 }
103 }
104
105 return $this;
106 }
107
108 protected function sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations): array
109 {
110 $pushMessage = parent::sendPushUsersAdd($usersToAdd, $oldRelations);
111
112 if (Loader::includeModule('pull'))
113 {
114 \CPullWatch::AddToStack('IM_PUBLIC_' . $this->getId(), $pushMessage);
115 }
116
117 return $pushMessage;
118 }
119
120 protected function sendPushUserDelete(int $userId, RelationCollection $oldRelations): array
121 {
122 $pushMessage = parent::sendPushUserDelete($userId, $oldRelations);
123
124 if (Loader::includeModule('pull'))
125 {
126 \CPullWatch::AddToStack('IM_PUBLIC_' . $this->getId(), $pushMessage);
127 }
128
129 return $pushMessage;
130 }
131}
sendPushUserDelete(int $userId, RelationCollection $oldRelations)
Definition OpenChat.php:120
sendPushUpdateMessage(Message $message)
Definition OpenChat.php:60
sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations)
Definition OpenChat.php:108
checkAccessWithoutCaching(int $userId)
Definition OpenChat.php:18
updateStateAfterUsersAdd(array $usersToAdd)
Definition OpenChat.php:93