25 private ?array $chatLastMessage =
null;
26 private bool $urlPreview =
true;
27 private bool $byEvent =
false;
28 private bool $withCheckAccess =
true;
33 $this->message = $message;
38 $this->message = $message;
45 $this->urlPreview = $urlPreview;
52 $this->byEvent = $byEvent;
59 $this->withCheckAccess =
false;
66 if ($this->withCheckAccess && !$this->
canUpdate())
71 $this->message->fill($fieldsToUpdate);
73 if ($this->message->isCompletelyEmpty())
75 return (
new Message\Delete\DeleteService($this->message))->delete();
78 if ($this->message->isViewedByOthers())
83 $filesFromText = $this->message->autocompleteParams($this->urlPreview)->uploadFileFromText();
84 $result = $this->message->save();
85 if (!$result->isSuccess())
92 SET DATE_UPDATE = NOW()
93 WHERE ITEM_MID = " . $this->message->getId()
96 $this->message->getChat()->sendPushUpdateMessage($this->message);
99 MessageTable::indexRecord($this->message->getId());
101 (
new UrlService())->updateUrlsFromMessage($this->message);
102 (
new FileService())->saveFilesFromMessage($filesFromText, $this->message);
104 $this->fireEventAfterMessageUpdate();
111 $isMessageDelete = $this->message->getParams()->get(
Params::IS_DELETED)->getValue() ===
true;
114 if ($isMessageDelete || $isForward)
119 $user = $this->getContext()->getUser();
120 $chat = $this->message->getChat();
122 if ($chat instanceof
Chat\
OpenLineChat && Loader::includeModule(
'imopenlines'))
129 if ($user->getId() === $this->message->getAuthorId())
131 return $chat->canUpdateOwnMessage();
137 if ($this->message->getAuthorId() === $user->getId())
145 private function getBotInChat(): array
148 $users = $this->message->getChat()->getRelations()->getUsers();
150 foreach ($users as $user)
154 $result[$user->getId()] = $user->getId();
161 private function fireEventAfterMessageUpdate(): void
163 $chat = $this->message->getChat();
165 'ID' => $this->message->getId(),
166 'CHAT_ID' => $this->message->getChatId(),
167 'AUTHOR_ID' => $this->message->getAuthorId(),
168 'MESSAGE' => $this->message->getMessage(),
169 'MESSAGE_OUT' => $this->message->getMessageOut(),
170 'DATE_CREATE' => $this->message->getDateCreate()->getTimestamp(),
171 'EMAIL_TEMPLATE' => $this->message->getEmailTemplate(),
172 'NOTIFY_TYPE' => $this->message->getNotifyType(),
173 'NOTIFY_MODULE' => $this->message->getNotifyModule(),
174 'NOTIFY_EVENT' => $this->message->getNotifyEvent(),
175 'NOTIFY_TAG' => $this->message->getNotifyTag(),
176 'NOTIFY_SUB_TAG' => $this->message->getNotifySubTag(),
177 'NOTIFY_TITLE' => $this->message->getNotifyTitle(),
178 'NOTIFY_BUTTONS' => $this->message->getNotifyButtons(),
179 'NOTIFY_READ' => $this->message->isNotifyRead(),
180 'IMPORT_ID' => $this->message->getImportId(),
181 'MESSAGE_TYPE' => $chat->getType(),
182 'CHAT_AUTHOR_ID' => $chat->getAuthorId(),
183 'CHAT_ENTITY_TYPE' => $chat->getEntityType(),
184 'CHAT_ENTITY_ID' => $chat->getEntityId(),
185 'CHAT_PARENT_ID' => $chat->getParentChatId(),
186 'CHAT_PARENT_MID' => $chat->getParentMessageId(),
187 'CHAT_ENTITY_DATA_1' => $chat->getEntityData1(),
188 'CHAT_ENTITY_DATA_2' => $chat->getEntityData2(),
189 'CHAT_ENTITY_DATA_3' => $chat->getEntityData3(),
190 'PARAMS' => $this->message->getParams()->toRestFormat(),
194 if ($chat instanceof
Chat\PrivateChat)
196 $messageFields[
'FROM_USER_ID'] = $this->message->getAuthorId();
197 $messageFields[
'TO_USER_ID'] = $chat->getCompanion($this->message->getAuthorId())->getId();
201 $messageFields[
'BOT_IN_CHAT'] = $this->getBotInChat();
205 'ID' => $this->message->getId(),
206 'TEXT' => $this->message->getMessage(),
207 'URL_PREVIEW' => $this->urlPreview,
209 'USER_ID' => $this->message->getAuthorId(),
210 'BY_EVENT' => $this->byEvent,
213 foreach(GetModuleEvents(
'im', self::EVENT_AFTER_MESSAGE_UPDATE,
true) as $event)
215 ExecuteModuleEventEx($event, [$this->message->getId(), $messageFields, $updateFlags]);
218 Bot::onMessageUpdate($this->message->getId(), $messageFields);
static getConnection($name="")