1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Chats.php
См. документацию.
1<?php
2
4
11
12class Chats implements Entity
13{
14 private array $chatIds = [];
15 private array $messageIds = [];
16 private array $recentChatIds = [];
17 private array $dialogIds = [];
18 private array $shortInfoChatIds = [];
19 private array $deletedChatIds = [];
20 private array $completeDeleteChatIds = [];
21 private bool $readAll = false;
22 private array $chats;
23 private RecentSync $recent;
24
25 public function add(Event $event): void
26 {
27 $entityId = $event->entityId;
28 switch ($event->eventName)
29 {
31 $this->shortInfoChatIds[$entityId] = $entityId;
32 $this->deletedChatIds[$entityId] = $entityId;
33 break;
35 $this->shortInfoChatIds[$entityId] = $entityId;
36 $this->completeDeleteChatIds[$entityId] = $entityId;
37 break;
39 $this->chatIds[$entityId] = $entityId;
40 break;
42 $this->readAll = true;
43 break;
44 }
45 }
46
47 private function getRecent(): RecentSync
48 {
49 $this->getChats();
50
51 if (!isset($this->recent))
52 {
53 $this->recent = RecentSync::getRecentSync($this->chatIds);
54
55 $entities = $this->recent->getEntityIds();
56 $this->recentChatIds = $entities['chatIds'];
57 $this->messageIds = $entities['messageIds'];
58 $this->dialogIds = $entities['dialogIds'];
59 }
60
61 return $this->recent;
62 }
63
64 public function getShortInfoChatIds(): array
65 {
66 return $this->shortInfoChatIds;
67 }
68
69 public function getMessageIds(): array
70 {
71 return $this->messageIds;
72 }
73
74 public function getChatItems(): ChatsSync
75 {
76 return new ChatsSync($this->getChats(), $this->getRecent());
77 }
78
79 private function getChats(): array
80 {
81 if (isset($this->chats))
82 {
83 return $this->chats;
84 }
85
86 $this->chats = [];
87 foreach ($this->chatIds as $chatId)
88 {
89 $chat = Chat::getInstance((int)$chatId);
90 if (
91 $chat instanceof Chat\NullChat
92 || $chat instanceof Chat\NotifyChat
93 )
94 {
95 unset($this->chatIds[$chatId]);
96 }
97 else
98 {
99 $this->fillDialogId($chat);
100 $this->chats[$chatId] = $chat;
101 }
102 }
103
104 return $this->chats;
105 }
106
107 private function fillDialogId(Chat $chat): void
108 {
109 if (!$chat instanceof PrivateChat)
110 {
111 return;
112 }
113
114 $dialogId = $this->dialogIds[$chat->getId()] ?? null;
115 if ($dialogId !== null)
116 {
117 $chat->setDialogId((string)$dialogId);
118 }
119 }
120
121 public static function getRestEntityName(): string
122 {
123 return 'chatSync';
124 }
125
126 public function toRestFormat(array $option = []): ?array
127 {
128 $this->getRecent();
129
130 $result = [
131 'addedRecent' => $this->recentChatIds,
132 'addedChats' => $this->chatIds,
133 'deletedChats' => $this->deletedChatIds,
134 'completeDeletedChats' => $this->completeDeleteChatIds,
135 ];
136
137 if ($this->readAll)
138 {
139 $result['readAllChats'] = true;
140 }
141
142 return $result;
143 }
144}
static getRestEntityName()
Определения Chats.php:121
getMessageIds()
Определения Chats.php:69
getChatItems()
Определения Chats.php:74
toRestFormat(array $option=[])
Определения Chats.php:126
add(Event $event)
Определения Chats.php:25
getShortInfoChatIds()
Определения Chats.php:64
const DELETE_EVENT
Определения Event.php:10
const READ_ALL_EVENT
Определения Event.php:13
const COMPLETE_DELETE_EVENT
Определения Event.php:11
const ADD_EVENT
Определения Event.php:12
static getRecentSync(array $chatIds)
Определения RecentSync.php:12
static getInstance()
Определения application.php:98
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
Определения ufield.php:9
$entityId
Определения payment.php:4
$event
Определения prolog_after.php:141
$option
Определения options.php:1711