Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PushService.php
1<?php
2
4
8use CPullWatch;
9
11{
12 protected function isPullEnable(): bool
13 {
14 return \Bitrix\Main\Loader::includeModule('pull');
15 }
16
17
18 public function sendPull(Message $message, ?array $extraParams = null): void
19 {
20 if (!$this->isPullEnable())
21 {
22 return;
23 }
24
25 $chat = $message->getChat();
26 $params = $message->getEnrichedParams();
27
28 $pullParams = $this->getPullFormatParams($message);
29 $users = $chat->getRelations()->getUserIds();
30
31 if ($chat->getType() === IM_MESSAGE_PRIVATE)
32 {
33 $pullParams['params']['toUserId'] = $chat->getCompanion()->getId();
34 $pullParams['params']['fromUserId'] = $message->getAuthorId();
35 }
36 else
37 {
38 $pullParams['params']['senderId'] = $message->getAuthorId();
39
40 if ($chat->getEntityType() === 'LINES')
41 {
42 $users = $this->getRecipients($chat);
43 }
44 }
45
46 $messageParams = $params->toPullFormat($extraParams);
47 $pullParams['params']['params'] = $messageParams;
48
49 \Bitrix\Pull\Event::add($users, $pullParams);
50
51 if ($chat->getType() === IM_MESSAGE_OPEN || $chat->getType() === IM_MESSAGE_OPEN_LINE)
52 {
53 CPullWatch::AddToStack('IM_PUBLIC_' . $chat->getId(), $pullParams);
54 }
55 }
56
57 protected function getPullFormatParams(Message $message): array
58 {
59 return [
60 'module_id' => 'im',
61 'command' => 'messageParamsUpdate',
62 'params' => [
63 'id' => $message->getId(),
64 'type' => $message->getChat()->getType() === IM_MESSAGE_PRIVATE ? 'private': 'chat',
65 'chatId' => $message->getChat()->getId(),
66 ],
67 'extra' => \Bitrix\Im\Common::getPullExtra(),
68 ];
69 }
70
71 protected function getRecipients(Chat $chat): array
72 {
73 $users = $chat->getRelations()->getUserIds();
74
75 foreach ($chat->getRelations()->getUsers() as $user)
76 {
77 if ($user->getExternalAuthId() === 'imconnector')
78 {
79 unset($users[$user->getId()]);
80 }
81 }
82
83 return $users;
84 }
85}
static getUsers($chatId, $options=[])
Definition chat.php:787
sendPull(Message $message, ?array $extraParams=null)