1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Sender.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Pull;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Result;
7use Bitrix\Main\Loader;
8use Bitrix\Pull\Error;
9
13class Sender
14{
21 public function send(Event $event): Result
22 {
23 if (!Loader::includeModule('pull'))
24 {
25 return (new Result())->addError(new \Bitrix\Im\V2\Error(\Bitrix\Im\V2\Error::PULL_NOT_INSTALLED));
26 }
27
28 $basePull = $event->getBase();
29 $results = [];
30
31 if ($event->isGlobal())
32 {
33 return $this->sendGlobal($basePull);
34 }
35
36 $chat = $event->getTarget();
37
38 if ($chat !== null && !$event->shouldSendToOnlySpecificRecipients())
39 {
40 $results = $this->processPublicSending($chat, $basePull);
41 }
42
43 foreach ($event->getPullByUsers() as $group)
44 {
45 $results[] = $this->sendPull($group->getRecipients(), $group->getParams());
46 }
47
48 if ($this->shouldSendMobilePush($chat, $event))
49 {
50 foreach ($event->getMobilePushByUsers() as $group)
51 {
52 $results[] = $this->sendPush($group->getRecipients(), $group->getParams());
53 }
54 }
55
56 return Result::merge(...$results);
57 }
58
59 protected function processPublicSending(Chat $chat, array $basePull): array
60 {
61 $results = [];
62
63 if ($chat->needToSendPublicPull())
64 {
65 $results[] = $this->sendByTag('IM_PUBLIC_'. $chat->getChatId(), $basePull);
66 }
67 if ($chat->getType() === Chat::IM_TYPE_OPEN_CHANNEL)
68 {
69 $results[] = $this->sendSharedPull($basePull);
70 }
71 if ($chat->getType() === Chat::IM_TYPE_COMMENT)
72 {
73 $results[] = $this->sendByTag('IM_PUBLIC_COMMENT_' . $chat->getParentChatId(), $basePull);
74 }
75
76 return $results;
77 }
78
79 protected function shouldSendMobilePush(?Chat $chat, Event $event): bool
80 {
81 return
82 $event->shouldSendMobilePush()
83 && $chat !== null
84 && !($chat instanceof Chat\CommentChat)
85 ;
86 }
87
88 protected function sendGlobal(array $pull): Result
89 {
90 return self::getPullEventResult(\CPullStack::AddShared($pull));
91 }
92
93 protected function sendByTag(string $tag, array $pull): Result
94 {
95 return self::getPullEventResult(\CPullWatch::AddToStack($tag, $pull));
96 }
97
98 protected function sendSharedPull(array $pull): Result
99 {
101 }
102
103 protected function sendPull(array $recipients, array $pull): Result
104 {
105 return self::getPullEventResult(\Bitrix\Pull\Event::add($recipients, $pull));
106 }
107
108 protected function sendPush(array $recipients, array $push): Result
109 {
110 return self::getPullEventResult(\Bitrix\Pull\Push::add($recipients, $push));
111 }
112
113 protected static function getPullEventResult(bool $isSuccess): Result
114 {
115 if ($isSuccess)
116 {
117 return new Result();
118 }
119
121 if ($error instanceof Error)
122 {
123 return (new Result())->addError(new \Bitrix\Main\Error($error->msg, $error->code, $error->params));
124 }
125
126 return new Result();
127 }
128}
static getType($chatData, bool $camelCase=true)
Определения chat.php:45
static sendSharedPull(array $pull)
Определения OpenChannelChat.php:124
const PULL_NOT_INSTALLED
Определения Error.php:10
sendGlobal(array $pull)
Определения Sender.php:88
sendByTag(string $tag, array $pull)
Определения Sender.php:93
sendPush(array $recipients, array $push)
Определения Sender.php:108
shouldSendMobilePush(?Chat $chat, Event $event)
Определения Sender.php:79
send(Event $event)
Определения Sender.php:21
static getPullEventResult(bool $isSuccess)
Определения Sender.php:113
sendPull(array $recipients, array $pull)
Определения Sender.php:103
processPublicSending(Chat $chat, array $basePull)
Определения Sender.php:59
sendSharedPull(array $pull)
Определения Sender.php:98
static merge(Result ... $results)
Определения Result.php:41
add($name, $value)
Определения configuration.php:141
Определения result.php:20
Определения error.php:15
static getLastError()
Определения event.php:822
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения BaseEvent.php:3
Определения ActionUuid.php:3
$event
Определения prolog_after.php:141
$error
Определения subscription_card_product.php:20