Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
SameChatMessageFilter.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Controller\Filter
;
4
5
use
Bitrix\Im\V2\Message
;
6
use
Bitrix\Im\V2\MessageCollection
;
7
use
Bitrix\Main\Engine\ActionFilter\Base
;
8
use
Bitrix\Main\Event
;
9
use
Bitrix\Main\EventResult
;
10
11
class
SameChatMessageFilter
extends
Base
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
}
Bitrix\Im\V2\Controller\Filter\SameChatMessageFilter
Definition
SameChatMessageFilter.php:12
Bitrix\Im\V2\Controller\Filter\SameChatMessageFilter\onBeforeAction
onBeforeAction(Event $event)
Definition
SameChatMessageFilter.php:14
Bitrix\Im\V2\Message\MessageError
Definition
MessageError.php:9
Bitrix\Im\V2\MessageCollection
Definition
MessageCollection.php:35
Bitrix\Im\V2\Message
Definition
Message.php:44
Bitrix\Im\V2\Registry\unsetByKeys
unsetByKeys(array $keys)
Definition
Registry.php:10
Bitrix\Im\V2\Sync\Event
Definition
Event.php:9
Bitrix\Main\Engine\ActionFilter\Base
Definition
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Definition
base.php:80
Bitrix\Main\Engine\ActionFilter\Base\getAction
getAction()
Definition
base.php:48
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Im\V2\Controller\Filter
Definition
ActionUuidHandler.php:3
Bitrix\Im\V2\Message
Definition
AdditionalMessagePopupItem.php:3
modules
im
lib
V2
Controller
Filter
SameChatMessageFilter.php
Создано системой
1.10.0