1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CollabChat.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Chat;
4
5use Bitrix\Disk\Driver;
6use Bitrix\Disk\Folder;
7use Bitrix\Im\Access\ChatAuthProvider;
8use Bitrix\Im\V2\Chat\Collab\CollabInfo;
9use Bitrix\Im\V2\Chat\Collab\GuestCounter;
10use Bitrix\Im\V2\Entity\User\User;
11use Bitrix\Im\V2\Entity\User\UserCollaber;
12use Bitrix\Im\V2\Integration\Socialnetwork\Group;
13use Bitrix\Im\V2\Permission\Action;
14use Bitrix\Im\V2\Permission\ActionGroup;
15use Bitrix\Im\V2\Relation\DeleteUserConfig;
16use Bitrix\Im\V2\RelationCollection;
17use Bitrix\Im\V2\Recent\Initializer;
18use Bitrix\Im\V2\Rest\PopupData;
19use Bitrix\Im\V2\Result;
20
21class CollabChat extends GroupChat
22{
23 protected const EXTRANET_CAN_SEE_HISTORY = true;
24
25 private const UNAVAILABLE_ACTION_GROUPS = [
26 ActionGroup::ManageUi,
27 ActionGroup::ManageSettings,
28 ActionGroup::ManageUsersDelete,
29 ActionGroup::ManageUsersAdd
30 ];
31 private const UNAVAILABLE_ACTIONS = [
32 Action::Leave,
33 Action::LeaveOwner,
34 Action::Update,
35 Action::Delete,
36 ];
37
38 protected function getDefaultType(): string
39 {
40 return self::IM_TYPE_COLLAB;
41 }
42
43 protected function prepareParams(array $params = []): Result
44 {
45 if (!isset($params['ENTITY_ID']))
46 {
47 return (new Result())->addError(new ChatError(ChatError::ENTITY_ID_EMPTY));
48 }
49
50 $params['ENTITY_TYPE'] = ExtendedType::Sonet->value;
51
52 return parent::prepareParams($params);
53 }
54
55 public function getPopupData(array $excludedList = []): PopupData
56 {
57 return parent::getPopupData($excludedList)->add(new CollabInfo($this));
58 }
59
60 public function getStorageId(): int
61 {
62 return Group::getStorageId((int)$this->getEntityId()) ?? 0;
63 }
64
65 protected function createDiskFolder(): ?Folder
66 {
67 $storage = \CIMDisk::GetStorage($this->chatId);
68 if (!$storage)
69 {
70 return null;
71 }
72
73 $folder = $storage->getFolderForUploadedFiles();
74 if (!$folder)
75 {
76 return null;
77 }
78
79 $this->setDiskFolderId($folder->getId())->save();
80 Driver::getInstance()->getRightsManager()->append($folder, $this->getAccessCodesForDiskFolder());
81 $accessProvider = new ChatAuthProvider;
82 $accessProvider->updateChatCodesByRelations($this->getId());
83
84 return $folder;
85 }
86
87 public function canDo(Action $action, mixed $target = null): bool
88 {
89 if (in_array($action, self::UNAVAILABLE_ACTIONS, true))
90 {
91 return false;
92 }
93
94 $actionGroup = ActionGroup::tryFromAction($action);
95
96 if (in_array($actionGroup, self::UNAVAILABLE_ACTION_GROUPS, true))
97 {
98 return false;
99 }
100
101 return parent::canDo($action, $target);
102 }
103
104 protected function updateStateAfterRelationsAdd(array $usersToAdd): self
105 {
106 Initializer::onAfterUsersAddToCollab($usersToAdd, $this->getId());
107
108 if (!empty($this->filterCollabers($usersToAdd)))
109 {
110 GuestCounter::cleanCache($this->chatId);
111 }
112
113 return parent::updateStateAfterRelationsAdd($usersToAdd);
114 }
115
116 protected function updateStateAfterUserDelete(int $deletedUserId, DeleteUserConfig $config): self
117 {
118 if (!empty($this->filterCollabers([$deletedUserId])))
119 {
120 GuestCounter::cleanCache($this->chatId);
121 }
122
123 return parent::updateStateAfterUserDelete($deletedUserId, $config);
124 }
125
126 protected function sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations): void
127 {
128 if (!empty($this->filterCollabers($usersToAdd)))
129 {
130 (new GuestCounter($this))->sendPushGuestCount();
131 }
132
133 parent::sendPushUsersAdd($usersToAdd, $oldRelations);
134 }
135
136 protected function sendPushUserDelete(int $userId, RelationCollection $oldRelations): void
137 {
138 if (!empty($this->filterCollabers([$userId])))
139 {
140 (new GuestCounter($this))->sendPushGuestCount();
141 }
142
143 parent::sendPushUserDelete($userId, $oldRelations);
144 }
145
146 protected function filterCollabers(array $userIds): array
147 {
148 return array_filter($userIds, fn (int $userId) => User::getInstance($userId) instanceof UserCollaber);
149 }
150
151 protected function needToSendMessageUserDelete(): bool
152 {
153 return false;
154 }
155}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
updateChatCodesByRelations(int $chatId)
Определения chatauthprovider.php:237
const ENTITY_ID_EMPTY
Определения ChatError.php:35
static cleanCache(int $chatId)
Определения GuestCounter.php:110
sendPushUserDelete(int $userId, RelationCollection $oldRelations)
Определения CollabChat.php:136
updateStateAfterRelationsAdd(array $usersToAdd)
Определения CollabChat.php:104
needToSendMessageUserDelete()
Определения CollabChat.php:151
getPopupData(array $excludedList=[])
Определения CollabChat.php:55
const EXTRANET_CAN_SEE_HISTORY
Определения CollabChat.php:23
prepareParams(array $params=[])
Определения CollabChat.php:43
filterCollabers(array $userIds)
Определения CollabChat.php:146
sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations)
Определения CollabChat.php:126
updateStateAfterUserDelete(int $deletedUserId, DeleteUserConfig $config)
Определения CollabChat.php:116
canDo(Action $action, mixed $target=null)
Определения CollabChat.php:87
add(PopupDataItem $item)
Определения PopupData.php:40
static getInstance()
Определения application.php:98
Определения result.php:20
static GetStorage(?int $chatId=null)
Определения im_disk.php:30
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$config
Определения quickway.php:69
if(empty($decryptedData)) $storage
Определения quickway.php:270
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$action
Определения file_dialog.php:21