Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Message.php
1<?php
2
4
12
13class Message extends Controller
14{
15 protected function getDefaultPreFilters()
16 {
17 return array_merge(
18 parent::getDefaultPreFilters(),
19 [
20 new \Bitrix\Rest\Engine\ActionFilter\Scope('im.import'),
21 new \Bitrix\Main\Engine\ActionFilter\Scope(\Bitrix\Main\Engine\ActionFilter\Scope::REST),
22 new \Bitrix\Rest\Engine\ActionFilter\AuthType(\Bitrix\Rest\Engine\ActionFilter\AuthType::APPLICATION)
23 ]
24 );
25 }
26
27 public function addAction(int $chatId, array $messages, CurrentUser $user): ?array
28 {
29 if (count($messages) > 2000)
30 {
31 $this->addError(new MessageError(MessageError::TOO_MANY_MESSAGES));
32
33 return null;
34 }
35
36 $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']);
37 if (!$chat)
38 {
40
41 return null;
42 }
43
44 $importService = new ImportService($chat, (int)$user->getId());
45
46 if (!$importService->hasAccess())
47 {
49
50 return null;
51 }
52
53 $addResult = $importService->addMessages($messages);
54
55 if (!$addResult->isSuccess())
56 {
57 $this->addErrors($addResult->getErrors());
58
59 return null;
60 }
61
62 return $this->convertKeysToCamelCase($addResult->getResult());
63 }
64
65 public function updateAction(array $messages, int $chatId, CurrentUser $user): ?array
66 {
67 if (count($messages) > 2000)
68 {
69 $this->addError(new MessageError(MessageError::TOO_MANY_MESSAGES));
70
71 return null;
72 }
73
74 $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']);
75 if (!$chat)
76 {
78
79 return null;
80 }
81
82 $importService = new ImportService($chat, (int)$user->getId());
83
84 if (!$importService->hasAccess())
85 {
87
88 return null;
89 }
90
91 $updateResult = $importService->updateMessages($messages);
92
93 if (!$updateResult->isSuccess())
94 {
95 $this->addErrors($updateResult->getErrors());
96
97 return null;
98 }
99
100 return $this->convertKeysToCamelCase($updateResult->getResult());
101 }
102}
static getById(int $id)
updateAction(array $messages, int $chatId, CurrentUser $user)
Definition Message.php:65
addAction(int $chatId, array $messages, CurrentUser $user)
Definition Message.php:27