28 private ?
array $chatLastMessage =
null;
29 private bool $byEvent =
false;
30 private bool $withCheckAccess =
true;
35 $this->message = $message;
41 $this->message = $message;
50 $this->sendingConfig->disableUrlPreview();
58 $this->byEvent = $byEvent;
65 $this->withCheckAccess =
false;
72 if ($this->withCheckAccess && !$this->
canUpdate())
79 $this->message->fill($fieldsToUpdate);
81 if ($this->message->isCompletelyEmpty())
83 return (DeleteService::getInstanceByMessage($this->message))->delete();
86 if ($this->message->isViewedByOthers())
91 $filesFromText = $this->message->autocompleteParams($this->sendingConfig)->uploadFileFromText();
92 $result = $this->message->save();
98 Application::getConnection()->queryExecute(
"
100 SET DATE_UPDATE = NOW()
101 WHERE ITEM_MID = " . $this->message->getId()
104 $this->message->getChat()->sendPushUpdateMessage($this->message);
107 MessageTable::indexRecord($this->message->getId());
109 (
new UrlService())->updateUrlsFromMessage($this->message);
110 (
new FileService())->saveFilesFromMessage($filesFromText, $this->message);
112 $this->fireEventAfterMessageUpdate();
122 $isMessageDelete = $this->message->getParams()->get(
Params::IS_DELETED)->getValue() ===
true;
125 if ($isMessageDelete || $isForward)
130 $user = $this->getContext()->getUser();
131 $chat = $this->message->getChat();
133 if ($chat instanceof
Chat\
OpenLineChat && Loader::includeModule(
'imopenlines'))
140 if (
$user->getId() === $this->message->getAuthorId())
142 return $chat->canUpdateOwnMessage();
148 if ($this->message->getAuthorId() ===
$user->getId())
156 private function getBotInChat():
array
159 $users = $this->message->getChat()->getRelations()->getUsers();
161 foreach ($users as
$user)
172 private function fireEventAfterMessageUpdate(): void
174 $chat = $this->message->getChat();
176 'ID' => $this->message->getId(),
177 'CHAT_ID' => $this->message->getChatId(),
178 'AUTHOR_ID' => $this->message->getAuthorId(),
179 'MESSAGE' => $this->message->getMessage(),
180 'MESSAGE_OUT' => $this->message->getMessageOut(),
181 'DATE_CREATE' => $this->message->getDateCreate()->getTimestamp(),
182 'EMAIL_TEMPLATE' => $this->message->getEmailTemplate(),
183 'NOTIFY_TYPE' => $this->message->getNotifyType(),
184 'NOTIFY_MODULE' => $this->message->getNotifyModule(),
185 'NOTIFY_EVENT' => $this->message->getNotifyEvent(),
186 'NOTIFY_TAG' => $this->message->getNotifyTag(),
187 'NOTIFY_SUB_TAG' => $this->message->getNotifySubTag(),
188 'NOTIFY_TITLE' => $this->message->getNotifyTitle(),
189 'NOTIFY_BUTTONS' => $this->message->getNotifyButtons(),
190 'NOTIFY_READ' => $this->message->isNotifyRead(),
191 'IMPORT_ID' => $this->message->getImportId(),
192 'MESSAGE_TYPE' => $chat->getType(),
193 'CHAT_AUTHOR_ID' => $chat->getAuthorId(),
194 'CHAT_ENTITY_TYPE' => $chat->getEntityType(),
195 'CHAT_ENTITY_ID' => $chat->getEntityId(),
196 'CHAT_PARENT_ID' => $chat->getParentChatId(),
197 'CHAT_PARENT_MID' => $chat->getParentMessageId(),
198 'CHAT_ENTITY_DATA_1' => $chat->getEntityData1(),
199 'CHAT_ENTITY_DATA_2' => $chat->getEntityData2(),
200 'CHAT_ENTITY_DATA_3' => $chat->getEntityData3(),
201 'PARAMS' => $this->message->getParams()->toRestFormat(),
208 $messageFields[
'TO_USER_ID'] = $chat->getCompanion($this->message->getAuthorId())->getId();
216 'ID' => $this->message->getId(),
217 'TEXT' => $this->message->getMessage(),
218 'URL_PREVIEW' => $this->urlPreview,
220 'USER_ID' => $this->message->getAuthorId(),
221 'BY_EVENT' => $this->byEvent,
231 $chat->onAfterMessageUpdate($this->message);
233 Sync\Logger::getInstance()->add(
234 new Sync\Event(Sync\Event::ADD_EVENT, Sync\Event::UPDATED_MESSAGE_ENTITY, $this->message->getId()),
235 static fn () => $chat->getRelations()->getUserIds(),