1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Push.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Link;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Common\ContextCustomer;
7use Bitrix\Im\V2\Rest\RestAdapter;
8use Bitrix\Main\Application;
9
10class Push
11{
12 use ContextCustomer;
13
14 protected const MODULE_ID = 'im';
15
16 protected array $events;
17 private static Push $instance;
18 private bool $isJobPlanned = false;
19
20 private function __construct()
21 {
22 }
23
24 public static function getInstance(): self
25 {
26 if (!isset(self::$instance))
27 {
28 self::$instance = new self();
29 }
30
31 return self::$instance;
32 }
33
34 public function sendFull(LinkRestConvertible $link, string $eventName, array $endpoint): void
35 {
36 $this->send((new RestAdapter($link))->toRestFormat(), $eventName, $endpoint);
37 }
38
39 public function sendIdOnly(LinkRestConvertible $link, string $eventName, array $endpoint): void
40 {
41 $this->send($link->toRestFormatIdOnly(), $eventName, $endpoint);
42 }
43
44 protected function send(array $params, string $eventName, array $endpoint): void
45 {
46 $pull = [
47 'module_id' => self::MODULE_ID,
48 'command' => $eventName,
49 'params' => $params,
51 ];
52 $event = ['params' => $pull];
53 if (isset($endpoint['CHAT_ID']))
54 {
55 $chat = Chat::getInstance((int)$endpoint['CHAT_ID']);
56 if ($chat->getType() === Chat::IM_TYPE_COMMENT)
57 {
58 $event['tag'] = 'IM_PUBLIC_COMMENT_' . $chat->getParentChatId();
59 }
60 else
61 {
62 $event['recipient'] = $chat->getRelations()->getUserIds();
63 }
64 }
65 elseif (isset($endpoint['RECIPIENT']))
66 {
67 $event['recipient'] = $endpoint['RECIPIENT'];
68 }
69 else
70 {
71 return;
72 }
73
74 $this->events[] = $event;
75
76 $this->deferRun();
77 }
78
79 protected function push(): void
80 {
81 if (!\Bitrix\Main\Loader::includeModule('pull'))
82 {
83 return;
84 }
85 foreach ($this->events as $event)
86 {
87 if (isset($event['recipient']))
88 {
89 \Bitrix\Pull\Event::add($event['recipient'], $event['params']);
90 }
91 if (isset($event['tag']))
92 {
93 \CPullWatch::AddToStack($event['tag'], $event['params']);
94 }
95 }
96 $this->isJobPlanned = false;
97 $this->events = [];
98 }
99
100 protected function deferRun(): void
101 {
102 if (!$this->isJobPlanned)
103 {
104 Application::getInstance()->addBackgroundJob(function () {
105 $this->push();
106 });
107 $this->isJobPlanned = true;
108 }
109 }
110}
static getPullExtra()
Определения common.php:127
static getInstance()
Определения application.php:98
static getInstance()
Определения servicelocator.php:33
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799