1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
MessageAnalytics.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Analytics;
6
7use Bitrix\Im\V2\Analytics\Event\MessageEvent;
8use Bitrix\Im\V2\Chat;
9use Bitrix\Im\V2\Chat\FavoriteChat;
10use Bitrix\Im\V2\Message;
11
13{
14 protected const SEND_MESSAGE = 'send_message';
15 protected const ADD_REACTION = 'add_reaction';
16 protected const SHARE_MESSAGE = 'share_message';
17 protected const DELETE_MESSAGE = 'delete_message';
18 protected const ATTACH_FILE = 'attach_file';
19
20 protected Message $message;
21
22 public function __construct(Message $message)
23 {
24 parent::__construct($message->getChat());
25 $this->message = $message;
26 }
27
28 public function addSendMessage(): void
29 {
30 $this->async(function () {
31 if ($this->message->getMessageId() === null)
32 {
33 return;
34 }
35
36 if ($this->message->isForward() || $this->message->isSystem())
37 {
38 return;
39 }
40
41 $this
42 ->createMessageEvent(self::SEND_MESSAGE)
43 ?->setType((new MessageContent($this->message))->getComponentName())
44 ?->send()
45 ;
46
47 $this->addAttachFilesEvent();
48 });
49 }
50
51 public function addAddReaction(string $reaction): void
52 {
53 $this->async(function () use ($reaction) {
54 $this
55 ->createMessageEvent(self::ADD_REACTION)
56 ?->setType($reaction)
57 ?->send()
58 ;
59 });
60 }
61
62 public function addShareMessage(Chat $targetChat): void
63 {
64 $this->async(function () use ($targetChat) {
65 $event =
66 $this
67 ->createMessageEvent(self::SHARE_MESSAGE)
68 ?->setType((new MessageContent($this->message))->getComponentName())
69 ;
70
71 if ($targetChat instanceof FavoriteChat)
72 {
73 $event?->setSection('notes');
74 }
75
76 $event?->send();
77 });
78 }
79
80 public function addDeleteMessage(string $messageType): void
81 {
82 $this->async(function () use ($messageType) {
83 $this
84 ->createMessageEvent(self::DELETE_MESSAGE)
85 ?->setType($messageType)
86 ?->send()
87 ;
88 });
89 }
90
91 protected function addAttachFilesEvent(): void
92 {
93 $files = $this->message->getFiles();
94 $fileCount = $files->count();
95 if ($fileCount < 1)
96 {
97 return;
98 }
99
100 $this
101 ->createMessageEvent(self::ATTACH_FILE)
102 ?->setFilesType($files)
103 ?->setFileP3($fileCount)
104 ?->send()
105 ;
106 }
107
108 protected function createMessageEvent(
109 string $eventName,
110 ): ?MessageEvent
111 {
112 if (!$this->isChatTypeAllowed($this->chat))
113 {
114 return null;
115 }
116
117 return (new MessageEvent($eventName, $this->chat, $this->userId));
118 }
119}
addAddReaction(string $reaction)
Определения MessageAnalytics.php:51
createMessageEvent(string $eventName,)
Определения MessageAnalytics.php:108
addShareMessage(Chat $targetChat)
Определения MessageAnalytics.php:62
__construct(Message $message)
Определения MessageAnalytics.php:22
addDeleteMessage(string $messageType)
Определения MessageAnalytics.php:80
Определения Uuid.php:3
$files
Определения mysql_to_pgsql.php:30
$event
Определения prolog_after.php:141