1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PushService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
13
15{
16 private const ADD_ANCHOR_EVENT = 'addAnchor';
17 private const DELETE_ANCHOR_EVENT = 'deleteAnchor';
18 private const DELETE_CHAT_ANCHORS_EVENT = 'deleteChatAnchors';
19 private const DELETE_ALL_ANCHORS_EVENT = 'deleteAllAnchors';
20
21 public function addMulti(AnchorCollection $anchorCollection): void
22 {
23 foreach ($anchorCollection as $anchorItem)
24 {
25 $this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
26 }
27 }
28
29 public function add(AnchorItem $anchorItem): void
30 {
31 $this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
32 }
33
34 public function deleteMulti(AnchorCollection $anchorCollection): void
35 {
36 foreach ($anchorCollection as $anchorItem)
37 {
38 $this->delete($anchorItem);
39 }
40 }
41
42 public function delete(AnchorItem $anchorItem): void
43 {
44 $this->send(self::DELETE_ANCHOR_EVENT, $anchorItem);
45 }
46
47 public function deleteByChat(int $chatId, int $userId): void
48 {
49 if (!Loader::includeModule('pull'))
50 {
51 return;
52 }
53
54 $chat = Chat::getInstance($chatId);
55
56 if ($chat instanceof Chat\PrivateChat)
57 {
58 $this->deleteByPrivateChat($chatId, $userId);
59
60 return;
61 }
62
63 $parameters = [
64 'dialogId' => $chat->getDialogId(),
65 'chatId' => $chatId,
66 'userId' => $userId,
67 ];
68
69 $pull = [
70 'module_id' => 'im',
71 'command' => static::DELETE_CHAT_ANCHORS_EVENT,
72 'params' => $parameters,
73 'extra' => Common::getPullExtra(),
74 ];
75
76 Event::add([$userId], $pull);
77 }
78
79 public function deleteAll(int $userId): void
80 {
81 if (!Loader::includeModule('pull'))
82 {
83 return;
84 }
85
86 $pull = [
87 'module_id' => 'im',
88 'command' => static::DELETE_ALL_ANCHORS_EVENT,
89 'params' => ['userId' => $userId],
90 'extra' => Common::getPullExtra(),
91 ];
92
93 Event::add($userId, $pull);
94 }
95
96 private function send(string $eventName, AnchorItem $anchorItem): void
97 {
98 if (!Loader::includeModule('pull'))
99 {
100 return;
101 }
102
103 $chat = Chat::getInstance($anchorItem->getChatId());
104
105 $parameters = [...$anchorItem->toRestFormat()];
106
107 if ($chat instanceof Chat\PrivateChat)
108 {
109 $this->sendToPrivateChat($parameters, $eventName, $anchorItem);
110
111 return;
112 }
113
114 $parameters['dialogId'] = $chat->getDialogId();
115 $pull = [
116 'module_id' => 'im',
117 'command' => $eventName,
118 'params' => $parameters,
119 'extra' => Common::getPullExtra(),
120 ];
121
122 Event::add([$anchorItem->getUserId()], $pull);
123 }
124
125 private function sendToPrivateChat(array $parameters, string $eventName, AnchorItem $anchorItem): void
126 {
128 $chat = Chat::getInstance($anchorItem->getChatId());
129
130 $recipientId = $anchorItem->getUserId();
131
132 $parameters['dialogId'] = $chat->getCompanion($recipientId)->getId();
133 Event::add($recipientId, [
134 'module_id' => 'im',
135 'command' => $eventName,
136 'params' => $parameters,
137 'extra' => Common::getPullExtra(),
138 ]);
139 }
140
141 private function deleteByPrivateChat(int $chatId, int $userId): void
142 {
144 $chat = Chat::getInstance($chatId);
145
146 $parameters = [
147 'dialogId' => $chat->getCompanion($userId)->getId(),
148 'chatId' => $chatId,
149 'userId' => $userId,
150 ];
151
152 Event::add($userId, [
153 'module_id' => 'im',
154 'command' => static::DELETE_CHAT_ANCHORS_EVENT,
155 'params' => $parameters,
156 'extra' => Common::getPullExtra(),
157 ]);
158 }
159}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения common.php:7
static getPullExtra()
Определения common.php:127
addMulti(AnchorCollection $anchorCollection)
Определения PushService.php:21
add(AnchorItem $anchorItem)
Определения PushService.php:29
deleteMulti(AnchorCollection $anchorCollection)
Определения PushService.php:34
deleteByChat(int $chatId, int $userId)
Определения PushService.php:47
deleteAll(int $userId)
Определения PushService.php:79
static getInstance()
Определения application.php:98
Определения event.php:5
Определения loader.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804