1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CheckMessageSend.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Controller\Filter;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Chat\ChatError;
7use Bitrix\Im\V2\Chat\PrivateChat;
8use Bitrix\Im\V2\Message\Delete\DisappearService;
9use Bitrix\Im\V2\Message\MessageError;
10use Bitrix\Main\Engine\ActionFilter\Base;
11use Bitrix\Main\Engine\Response\Converter;
12use Bitrix\Main\Event;
13use Bitrix\Main\EventResult;
14use CIMChat;
15
17{
18 private string $actionName;
19
20 public function __construct(string $actionName)
21 {
22 parent::__construct();
23 $this->actionName = $actionName;
24 }
25
26 public function onBeforeAction(Event $event)
27 {
28 $arguments = $this->getAction()->getArguments();
29 $chat = $arguments['chat'];
30
31 if (!$chat instanceof Chat)
32 {
33 $this->addError(new ChatError(ChatError::NOT_FOUND, 'Chat not found'));
34
35 return new EventResult(EventResult::ERROR, null, null, $this);
36 }
37
38 $result = $this->canPost($chat);
39 if (!$result)
40 {
41 $this->addError(new ChatError(ChatError::ACCESS_DENIED, 'Access denied'));
42
43 return new EventResult(EventResult::ERROR, null, null, $this);
44 }
45
46 if (!$chat->checkAllowedAction('SEND'))
47 {
48 $this->addError(new ChatError(
50 'It is forbidden to send messages to this chat'
51 ));
52
53 return new EventResult(EventResult::ERROR, null, null, $this);
54 }
55
56 return null;
57 }
58
59 private function canPost(Chat $chat): bool
60 {
61 if ($chat instanceof PrivateChat)
62 {
63 return true;
64 }
65
66 return $chat->canDo($this->actionName);
67 }
68}
const ACCESS_DENIED
Определения ChatError.php:19
const NOT_FOUND
Определения ChatError.php:20
addError(Error $error)
Определения base.php:80
$result
Определения get_property_values.php:14
$event
Определения prolog_after.php:141