1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ChatsSync.php
См. документацию.
1<?php
2
4
18
20{
21 use ContextCustomer;
22
24
26 {
27 $this->recent = $recent;
28
29 parent::__construct($chats);
30 }
31
32 public function toRestFormat(array $option = []): array
33 {
34 $rest = [];
35
36 Chat::fillSelfRelations($this->chats);
37 $this->fillAllForRest();
38 $this->fillDialogIds();
39
40 foreach ($this->chats as $chat)
41 {
42 $restData = $chat->toRestFormat(['CHAT_SHORT_FORMAT' => true]);
43 $rest[] = array_merge($restData, $this->getSelfAdditionalParams($chat));
44 }
45
46 return $rest;
47 }
48
49 protected function getSelfAdditionalParams(Chat $chat): array
50 {
51 return [
52 'counter' => $chat->getUserCounter(),
53 'dateCreate' => $chat->getDateCreate()?->format('c'),
54 'lastMessageId' => $chat->getLastMessageId(),
55 'lastId' => $chat->getLastId(),
56 'managerList' => $chat->getManagerList(false),
57 'markedId' => $chat->getMarkedId(),
58 'messageCount' => $chat->getMessageCount(),
59 'public' => $chat->getPublicOption() ?? '',
60 'unreadId' => $chat->getUnreadId(),
61 'userCounter' => $chat->getUserCount(),
62 ];
63 }
64
65 protected function fillAllForRest(): void
66 {
67 $chatIds = $this->getChatIds();
68
69 $nonCachedData = $this->fillNonCachedData($chatIds);
71 $markedIds = $this->fillMarkedIds($chatIds);
72
73 $this->fillData($nonCachedData, $counters, $markedIds);
74 }
75
76 protected function fillData(array $nonCachedData, array $counters, array $markedIds): void
77 {
78 foreach ($nonCachedData as $chatData)
79 {
80 $chatId = (int)$chatData['ID'];
81 $chat = $this->chats[$chatId] ?? null;
82 if ($chat === null)
83 {
84 continue;
85 }
86
87 $chat
88 ->setMessageCount((int)$chatData['MESSAGE_COUNT'])
89 ->setUserCount((int)$chatData['USER_COUNT'])
90 ->setLastMessageId((int)$chatData['LAST_MESSAGE_ID'])
91 ->setMarkedId($markedIds[$chatId] ?? 0)
92 ->setUserCounter($counters[$chatId] ?? 0)
93 ->markFilledNonCachedData(true)
94 ;
95 }
96 }
97
99 {
100 if (empty($chatIds))
101 {
102 return [];
103 }
104
105 return ChatTable::query()
106 ->setSelect(array_merge(ChatFactory::NON_CACHED_FIELDS, ['ID']))
107 ->whereIn('ID', $chatIds)
108 ->fetchAll()
109 ;
110 }
111
112 protected function fillCounters(array $chatIds): array
113 {
114 $readService = new ReadService();
115
116 return $readService->getCounterService()->getForEachChat($chatIds);
117 }
118
119 protected function fillMarkedIds(array $chatIds): array
120 {
121 if (!empty($this->recent))
122 {
123 return $this->fillMarkedIdsByRecent();
124 }
125
126 return Recent::getMarkedIdByChatIds($this->getContext()->getUserId(), $chatIds);
127 }
128
129 protected function fillMarkedIdsByRecent(): array
130 {
131 $markedIds = [];
132 foreach ($this->recent as $recentItem)
133 {
134 $markedIds[$recentItem->getChatId()] = $recentItem->getMarkedId();
135 }
136
137 return $markedIds;
138 }
139
140 protected function getUsers(): array
141 {
142 $userIds =
143 !empty($this->chats)
144 ? [$this->getContext()->getUserId()]
145 : []
146 ;
147
148 foreach ($this->chats as $chat)
149 {
150 if ($chat instanceof Chat\PrivateChat)
151 {
152 $userIds[] = (int)$chat->getDialogId();
153 }
154 }
155
156 return $userIds;
157 }
158
159 public function getPopupData(array $excludedList = []): PopupData
160 {
161 $this->fillDialogIds();
162
163 return new PopupData([
164 CopilotPopupItem::getInstanceByChatIds($this->getChatIds()),
165 (new MessagesAutoDeleteConfigs($this->getChatIds()))->showDefaultValues(),
166 new UserPopupItem($this->getUsers()),
167 $this->recent,
168 ], $excludedList);
169 }
170}
static getMessageCount($chatId, $userId=null)
Определения chat.php:363
static getMarkedIdByChatIds(int $userId, array $chatIds)
Определения recent.php:1878
toRestFormat(array $option=[])
Определения ChatsSync.php:32
RecentSync $recent
Определения ChatsSync.php:23
fillAllForRest()
Определения ChatsSync.php:65
getPopupData(array $excludedList=[])
Определения ChatsSync.php:159
fillCounters(array $chatIds)
Определения ChatsSync.php:112
fillMarkedIdsByRecent()
Определения ChatsSync.php:129
getSelfAdditionalParams(Chat $chat)
Определения ChatsSync.php:49
__construct(array $chats, RecentSync $recent)
Определения ChatsSync.php:25
fillNonCachedData(array $chatIds)
Определения ChatsSync.php:98
fillMarkedIds(array $chatIds)
Определения ChatsSync.php:119
fillData(array $nonCachedData, array $counters, array $markedIds)
Определения ChatsSync.php:76
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
trait ContextCustomer
Определения ContextCustomer.php:12
Определения ChatsSync.php:3
$option
Определения options.php:1711
$counters
Определения options.php:100