1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
MessageService.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Message;
4
5use Bitrix\Im\Model\MessageTable;
6use Bitrix\Im\V2\Common\ContextCustomer;
7use Bitrix\Im\V2\Message;
8use Bitrix\Im\V2\MessageCollection;
9use Bitrix\Im\V2\Result;
10use Bitrix\Im\V2\Service\Context;
11
13{
14 use ContextCustomer;
15
17 private Message $message;
18
19 public function __construct(Message $message)
20 {
21 $this->message = $message;
22 }
23
24 public function getMessageContext(int $range, array $select = []): Result
25 {
26 $result = new Result();
27
28 $messageId = $this->message->getMessageId() ?? 0;
29 $chat = $this->message->getChat();
30
31 $startId = $chat->getStartId();
32
33 $idsBefore = [];
34 $idsAfter = [];
35 if ($range > 0)
36 {
37 $idsBefore = MessageTable::query()
38 ->setSelect(['ID'])
39 ->where('ID', '<', $messageId)
40 ->where('ID', '>=', $startId)
41 ->where('CHAT_ID', $chat->getChatId())
42 ->setOrder(['DATE_CREATE' => 'DESC', 'ID' => 'DESC'])
43 ->setLimit($range)
44 ->fetchCollection()
45 ->getIdList()
46 ;
47 $idsAfter = MessageTable::query()
48 ->setSelect(['ID'])
49 ->where('ID', '>', $messageId)
50 ->where('CHAT_ID', $chat->getChatId())
51 ->setOrder(['DATE_CREATE' => 'ASC', 'ID' => 'ASC'])
52 ->setLimit($range)
53 ->fetchCollection()
54 ->getIdList()
55 ;
56 }
57 $targetMessage = $messageId < $startId ? [] : [$messageId];
58
59 $ids = array_merge($idsBefore, $targetMessage, $idsAfter);
60
61 if (empty($ids))
62 {
63 return $result->setResult(new MessageCollection());
64 }
65
66 if (empty($select))
67 {
68 return $result->setResult(new MessageCollection($ids));
69 }
70
71 $ormCollection = MessageTable::query()->whereIn('ID', $ids)->setSelect($select)->fetchCollection();
72
73 return $result->setResult(new MessageCollection($ormCollection));
74 }
75
76 public static function deleteByChatId(int $chatId, int $userId): Result
77 {
78 MessageTable::deleteBatch(['=CHAT_ID' => $chatId]);
79 $readService = new ReadService($userId);
80 $readService->deleteByChatId($chatId);
81
82 return new Result();
83 }
84
86 {
87 $wasFilteredByTariffRestrictions = $rest['tariffRestrictions']['isHistoryLimitExceeded'] ?? false;
88 $rest['hasPrevPage'] =
89 $this->getCountHigherMessages($messages, $this->message->getId() ?? 0) >= $range
90 && !$wasFilteredByTariffRestrictions
91 ;
92 $lastSelectedId = $this->getLastSelectedId($messages);
93 $lastMessageIdInChat = $this->message->getChat()->getLastMessageId();
94 $rest['hasNextPage'] = $lastSelectedId > 0 && $lastMessageIdInChat > 0 && $lastSelectedId < $lastMessageIdInChat;
95
96 return $rest;
97 }
98
99 private function getCountHigherMessages(MessageCollection $messages, int $id): int
100 {
101 $count = 0;
102
103 foreach ($messages as $message)
104 {
105 if ($message->getId() < $id)
106 {
107 ++$count;
108 }
109 }
110
111 return $count;
112 }
113
114 private function getLastSelectedId(MessageCollection $messages): int
115 {
116 return max($messages->getIds() ?: [0]);
117 }
118
123 public static function getMultipleActionMessageLimit(): int
124 {
125 return self::MAX_MESSAGES_COUNT_FOR_MULTIPLE_ACTIONS;
126 }
127}
$count
Определения admin_tab.php:4
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getMultipleActionMessageLimit()
Определения MessageService.php:123
getMessageContext(int $range, array $select=[])
Определения MessageService.php:24
const MAX_MESSAGES_COUNT_FOR_MULTIPLE_ACTIONS
Определения MessageService.php:16
static deleteByChatId(int $chatId, int $userId)
Определения MessageService.php:76
__construct(Message $message)
Определения MessageService.php:19
fillContextPaginationData(array $rest, MessageCollection $messages, int $range)
Определения MessageService.php:85
Определения result.php:20
</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
$select
Определения iblock_catalog_list.php:194
Определения Uuid.php:3
$message
Определения payment.php:8
$messages
Определения template.php:8