Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
CheckMessageSend.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Controller\Filter
;
4
5
use
Bitrix\Im\V2\Chat
;
6
use
Bitrix\Im\V2\Chat\ChatError
;
7
use
Bitrix\Im\V2\Chat\PrivateChat
;
8
use
Bitrix\Im\V2\Message\Delete\DisappearService
;
9
use
Bitrix\Im\V2\Message\MessageError
;
10
use
Bitrix\Main\Engine\ActionFilter\Base
;
11
use
Bitrix\Main\Engine\Response\Converter
;
12
use
Bitrix\Main\Event
;
13
use
Bitrix\Main\EventResult
;
14
use CIMChat;
15
16
class
CheckMessageSend
extends
Base
17
{
18
public
function
onBeforeAction
(
Event
$event)
19
{
20
$arguments = $this->
getAction
()->getArguments();
21
$chat = $arguments[
'chat'
];
22
23
if
(!$chat instanceof
Chat
)
24
{
25
$this->
addError
(
new
ChatError
(
ChatError::NOT_FOUND
,
'Chat not found'
));
26
27
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
28
}
29
30
$result = $this->canPost($chat);
31
if
(!$result)
32
{
33
$this->
addError
(
new
ChatError
(
ChatError::ACCESS_DENIED
,
'Access denied'
));
34
35
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
36
}
37
38
if
(!$chat->checkAllowedAction(
'SEND'
))
39
{
40
$this->
addError
(
new
ChatError
(
41
ChatError::ACCESS_DENIED
,
42
'It is forbidden to send messages to this chat'
43
));
44
45
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
46
}
47
48
return
null
;
49
}
50
51
private
function
canPost(
Chat
$chat): bool
52
{
53
if
($chat instanceof
PrivateChat
)
54
{
55
return
true
;
56
}
57
58
$userRole = $chat->getRole();
59
$chatRole = $chat->getCanPost();
60
61
return
Chat\Permission::compareRole($userRole, $chatRole);
62
}
63
}
Bitrix\Im\Chat
Definition
chat.php:19
Bitrix\Im\V2\Chat\ChatError
Definition
ChatError.php:9
Bitrix\Im\V2\Chat\ChatError\ACCESS_DENIED
const ACCESS_DENIED
Definition
ChatError.php:21
Bitrix\Im\V2\Chat\ChatError\NOT_FOUND
const NOT_FOUND
Definition
ChatError.php:22
Bitrix\Im\V2\Chat\PrivateChat
Definition
PrivateChat.php:33
Bitrix\Im\V2\Controller\Filter\CheckMessageSend
Definition
CheckMessageSend.php:17
Bitrix\Im\V2\Controller\Filter\CheckMessageSend\onBeforeAction
onBeforeAction(Event $event)
Definition
CheckMessageSend.php:18
Bitrix\Im\V2\Message\Delete\DisappearService
Definition
DisappearService.php:13
Bitrix\Im\V2\Message\MessageError
Definition
MessageError.php:9
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\Engine\Response\Converter
Definition
converter.php:8
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Im\V2\Chat
Definition
ChannelChat.php:3
Bitrix\Im\V2\Controller\Filter
Definition
ActionUuidHandler.php:3
modules
im
lib
V2
Controller
Filter
CheckMessageSend.php
Создано системой
1.10.0