1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ReadService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Anchor;
6
7use Bitrix\Im\Model\AnchorTable;
8use Bitrix\Im\V2\Anchor\DI\AnchorContainer;
9use Bitrix\Im\V2\Anchor\Push\PushService;
10use Bitrix\Im\V2\Common\ContextCustomer;
11use Bitrix\Im\V2\Result;
12use Bitrix\Main\Application;
13use Bitrix\Main\Diag\ExceptionHandler;
14use Bitrix\Main\SystemException;
15
17{
18 use ContextCustomer;
19
20 private PushService $pushService;
21 private AnchorProvider $anchorProvider;
22 private ExceptionHandler $exceptionHandler;
23
24 public function __construct()
25 {
26 $this->init();
27 }
28
29 public function read(array $messageIds, ?int $userId = null): Result
30 {
31 $result = new Result();
32
33 if (empty($messageIds))
34 {
35 return $result;
36 }
37
38 $userId ??= $this->getContext()->getUserId();
39
40 $filter = [
41 'USER_ID' => $userId,
42 'MESSAGE_ID' => $messageIds,
43 ];
44
45 try
46 {
47 $anchorCollection = AnchorCollection::find($filter);
48 if ($anchorCollection->isEmpty())
49 {
50 return $result;
51 }
52
53 $deleteResult = $anchorCollection->delete();
54 if (!$deleteResult->isSuccess())
55 {
56 return $result->addErrors($deleteResult->getErrors());
57 }
58 }
59 catch (SystemException $exception)
60 {
61 $this->exceptionHandler->writeToLog($exception);
62
63 return $result->addError(new AnchorError(AnchorError::UNEXPECTED));
64 }
65
66 $this->anchorProvider->cleanCache($userId);
67
68 $this->pushService->deleteMulti($anchorCollection);
69
70 return $result;
71 }
72
73 public function readByMessageIds(array $messageIds): Result
74 {
75 $result = new Result();
76
77 if (empty($messageIds))
78 {
79 return $result;
80 }
81
82 $filter = [
83 'MESSAGE_ID' => $messageIds,
84 ];
85
86 try
87 {
88 $anchorCollection = AnchorCollection::find($filter);
89 if ($anchorCollection->isEmpty())
90 {
91 return $result;
92 }
93
94 $deleteResult = $anchorCollection->delete();
95 if (!$deleteResult->isSuccess())
96 {
97 return $result->addErrors($deleteResult->getErrors());
98 }
99 }
100 catch (SystemException $exception)
101 {
102 $this->exceptionHandler->writeToLog($exception);
103
104 return $result->addError(new AnchorError(AnchorError::UNEXPECTED));
105 }
106
107 $this->anchorProvider->cleanUsersCache((array)$anchorCollection->getUserIdList());
108
109 $this->pushService->deleteMulti($anchorCollection);
110
111 return $result;
112 }
113
114 public function readAll(?int $userId = null): Result
115 {
116 $result = new Result();
117
118 $userId ??= $this->getContext()->getUserId();
119
120 if ($userId <= 0)
121 {
122 return $result;
123 }
124
125 try
126 {
127 AnchorTable::deleteByFilter(['USER_ID' => $userId]);
128 }
129 catch (SystemException $exception)
130 {
131 $this->exceptionHandler->writeToLog($exception);
132
133 return $result->addError(new AnchorError(AnchorError::UNEXPECTED));
134 }
135
136 $this->pushService->deleteAll($userId);
137
138 $this->anchorProvider->cleanCache($userId);
139
140 return $result;
141 }
142
143 public function readByChatId(int $chatId, ?int $userId = null): Result
144 {
145 $result = new Result();
146
147 $userId ??= $this->getContext()->getUserId();
148
149 if ($userId <= 0 || $chatId <= 0)
150 {
151 return $result;
152 }
153
154 try
155 {
156 AnchorTable::deleteByFilter(['CHAT_ID' => $chatId, 'USER_ID' => $userId]);
157 }
158 catch (SystemException $exception)
159 {
160 $this->exceptionHandler->writeToLog($exception);
161
162 return $result->addError(new AnchorError(AnchorError::UNEXPECTED));
163 }
164
165 $this->pushService->deleteByChat($chatId, $userId);
166
167 $this->anchorProvider->cleanCache($userId);
168
169 return $result;
170 }
171
172 private function init(): void
173 {
174 $this->pushService = AnchorContainer::getInstance()->getPushService();
175 $this->anchorProvider = AnchorContainer::getInstance()->getAnchorProvider();
176 $this->exceptionHandler = Application::getInstance()->getExceptionHandler();
177 }
178}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static find(array $filter, array $order=['MESSAGE_ID'=> 'desc'], ?int $limit=null, ?Context $context=null)
Определения AnchorCollection.php:35
read(array $messageIds, ?int $userId=null)
Определения ReadService.php:29
readAll(?int $userId=null)
Определения ReadService.php:114
readByChatId(int $chatId, ?int $userId=null)
Определения ReadService.php:143
readByMessageIds(array $messageIds)
Определения ReadService.php:73
Определения result.php:20
static getInstance()
Определения servicelocator.php:33
</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
$filter
Определения iblock_catalog_list.php:54