1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CounterServiceLegacy.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Message;
4
5use Bitrix\Im\Model\RecentTable;
6use Bitrix\Im\Model\RelationTable;
7use Bitrix\Im\V2\Chat;
8use Bitrix\Main\SystemException;
9
11{
12 protected const CACHE_PATH = '/bx/im/counter/';
13
14 protected const DEFAULT_COUNTERS = [
15 'TYPE' => [
16 'ALL' => 0,
17 'NOTIFY' => 0,
18 'CHAT' => 0,
19 'LINES' => 0,
20 'DIALOG' => 0,
21 'MESSENGER' => 0,
22 ],
23 'CHAT' => [],
24 'CHAT_MUTED' => [],
25 'CHAT_UNREAD' => [],
26 'LINES' => [],
27 'DIALOG' => [],
28 'DIALOG_UNREAD' => [],
29 ];
30
31 protected function countUnreadMessages(?array $chatIds = null): void
32 {
33 $counters = $this->getCountersForEachChat($chatIds);
34
35 $privateChatIds = [];
36 foreach ($counters as $counter)
37 {
38 if ($counter['CHAT_TYPE'] === \IM_MESSAGE_PRIVATE)
39 {
40 $privateChatIds[] = $counter['CHAT_ID'];
41 }
42 }
43
44 $chatIdToDialogId = $this->getMapChatToDialog($privateChatIds);
45
46 foreach ($counters as $counter)
47 {
48 $chatId = (int)$counter['CHAT_ID'];
49 $count = (int)$counter['COUNT'];
50 if ($counter['IS_MUTED'] === 'Y')
51 {
52 $this->setFromMutedChat($chatId, $count);
53 }
54 else if ($counter['CHAT_TYPE'] === \IM_MESSAGE_SYSTEM)
55 {
56 $this->setFromNotify($count);
57 }
58 else if ($counter['CHAT_TYPE'] === \IM_MESSAGE_OPEN_LINE)
59 {
60 $this->setFromLine($chatId, $count);
61 }
62 else if ($counter['CHAT_TYPE'] === \IM_MESSAGE_PRIVATE && isset($chatIdToDialogId[$chatId]))
63 {
64 $this->setFromDialog($chatIdToDialogId[$chatId], $count);
65 }
66 else if ($counter['CHAT_TYPE'] === Chat::IM_TYPE_COPILOT)
67 {
68 // nothing
69 }
70 else
71 {
72 $this->setFromChat($chatId, $count);
73 }
74 $this->countersByChatIds[$chatId] = $count;
75 }
76 }
77 protected function getUnreadChats(?bool $isMuted = null): array
78 {
79 $query = RecentTable::query()
80 ->setSelect(['CHAT_ID' => 'ITEM_CID', 'IS_MUTED' => 'RELATION.NOTIFY_BLOCK', 'DIALOG_ID' => 'ITEM_ID', 'ITEM_TYPE'])
81 ->where('USER_ID', $this->getContext()->getUserId())
82 ->where('UNREAD', true)
83 ;
84 if (isset($isMuted))
85 {
86 $query->where('IS_MUTED', $isMuted);
87 }
88
89 return $query->fetchAll();
90 }
91
92 protected function countUnreadChats(): void
93 {
94 $unreadChats = $this->getUnreadChats();
95
96 foreach ($unreadChats as $unreadChat)
97 {
98 if ($unreadChat['ITEM_TYPE'] === \IM_MESSAGE_PRIVATE)
99 {
100 $this->setUnreadDialog((int)$unreadChat['DIALOG_ID']);
101 }
102 else
103 {
104 $this->setUnreadChat((int)$unreadChat['CHAT_ID'], $unreadChat['IS_MUTED'] === 'Y');
105 }
106 }
107 }
108
109 protected function setUnreadDialog(int $id): void
110 {
111 $this->counters['TYPE']['ALL']++;
112 $this->counters['TYPE']['DIALOG']++;
113 $this->counters['TYPE']['MESSENGER']++;
114 $this->counters['DIALOG_UNREAD'][] = $id;
115 }
116
117 protected function setFromDialog(int $id, int $count): void
118 {
119 $this->counters['TYPE']['ALL'] += $count;
120 $this->counters['TYPE']['DIALOG'] += $count;
121 $this->counters['TYPE']['MESSENGER'] += $count;
122 $this->counters['DIALOG'][$id] = $count;
123 }
124
125 protected function getMapChatToDialog(array $privateChatIds)
126 {
127 if (empty($privateChatIds))
128 {
129 return [];
130 }
131
132 $result = RelationTable::query()
133 ->setSelect(['USER_ID', 'CHAT_ID'])
134 ->whereNot('USER_ID', $this->getContext()->getUserId())
135 ->whereIn('CHAT_ID', $privateChatIds)
136 ->fetchAll()
137 ;
138
139 $map = [];
140
141 foreach ($result as $row)
142 {
143 $map[$row['CHAT_ID']] = $row['USER_ID'];
144 }
145
146 return $map;
147 }
148}
$count
Определения admin_tab.php:4
setUnreadChat(int $id, bool $isMuted)
Определения CounterService.php:698
setFromNotify(int $count)
Определения CounterService.php:743
setFromLine(int $id, int $count)
Определения CounterService.php:749
setFromMutedChat(int $id, int $count)
Определения CounterService.php:738
getCountersForEachChat(?array $chatIds=null, bool $forCurrentUser=true)
Определения CounterService.php:857
setFromChat(int $id, int $count)
Определения CounterService.php:789
getUnreadChats(?bool $isMuted=null)
Определения CounterServiceLegacy.php:77
setFromDialog(int $id, int $count)
Определения CounterServiceLegacy.php:117
countUnreadMessages(?array $chatIds=null)
Определения CounterServiceLegacy.php:31
getMapChatToDialog(array $privateChatIds)
Определения CounterServiceLegacy.php:125
</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
$query
Определения get_search.php:11
const IM_MESSAGE_SYSTEM
Определения include.php:21
const IM_MESSAGE_PRIVATE
Определения include.php:22
const IM_MESSAGE_OPEN_LINE
Определения include.php:26
$map
Определения config.php:5
$counter
Определения options.php:5