Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
SameChatMessageFilter.php
1<?php
2
4
10
12{
13
14 public function onBeforeAction(Event $event)
15 {
16 foreach ($this->getAction()->getArguments() as $argument)
17 {
18 if ($argument instanceof MessageCollection)
19 {
20 $commonChatId = $argument->getCommonChatId();
21
22 if ($commonChatId === null)
23 {
24 $this->addError(new Message\MessageError(Message\MessageError::DIFFERENT_CHAT_ERROR));
25
26 return new EventResult(EventResult::ERROR, null, null, $this);
27 }
28
29 $this->filterMessageByChatId($argument, $commonChatId);
30 }
31 }
32
33 return null;
34 }
35
36 private function filterMessageByChatId(MessageCollection $messages, int $chatId): void
37 {
38 $keysToUnset = [];
39
40 foreach ($messages as $key => $message)
41 {
42 if ($message->getChatId() !== $chatId)
43 {
44 $keysToUnset[$key] = $key;
45 }
46 }
47
48 $messages->unsetByKeys($keysToUnset);
49 }
50
51}
unsetByKeys(array $keys)
Definition Registry.php:10