[REF] mail: clean code for message update

As a bonus, add cross-tab update for current user in chatter.

Part of task-3265211

closes odoo/odoo#120018

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2023-04-28 12:26:43 +02:00
parent df187c4cc2
commit 09ac15e2dd
5 changed files with 10 additions and 27 deletions
-5
View File
@@ -83,8 +83,3 @@ class ThreadController(http.Controller):
request.env[message_sudo.model].browse([message_sudo.res_id])._message_update_content(
message_sudo, body, attachment_ids=attachment_ids
)
return {
"id": message_sudo.id,
"body": message_sudo.body,
"attachment_ids": message_sudo.attachment_ids._attachment_format(),
}
@@ -628,17 +628,6 @@ class Channel(models.Model):
if not message.message_type == 'comment':
raise UserError(_("Only messages type comment can have their content updated on model 'discuss.channel'"))
def _message_update_content_after_hook(self, message):
self.ensure_one()
self.env['bus.bus']._sendone(self, 'mail.record/insert', {
'Message': {
'id': message.id,
'body': message.body,
'attachment_ids': message.attachment_ids._attachment_format(),
}
})
return super()._message_update_content_after_hook(message=message)
def _message_subscribe(self, partner_ids=None, subtype_ids=None, customer_ids=None):
""" Do not allow follower subscription on channels. Only members are
considered. """
+7 -5
View File
@@ -4057,11 +4057,13 @@ class MailThread(models.AbstractModel):
empty_messages._cleanup_side_records()
empty_messages.write({'pinned_at': None})
return self._message_update_content_after_hook(message)
def _message_update_content_after_hook(self, message):
""" Hook to add custom behavior after having updated the message content. """
return True
self.env['bus.bus']._sendone(message._bus_notification_target(), 'mail.record/insert', {
'Message': {
'id': message.id,
'body': message.body,
'attachment_ids': message.attachment_ids._attachment_format(),
}
})
# ------------------------------------------------------
# CONTROLLERS
@@ -1,6 +1,5 @@
/** @odoo-module */
import { markup } from "@odoo/owl";
import { Message } from "./message_model";
import { removeFromArrayWithPredicate } from "../utils/arrays";
import { convertBrToLineBreak, prettifyMessageContent } from "../utils/format";
@@ -34,15 +33,13 @@ export class MessageService {
return;
}
const validMentions = this.getMentionsFromText(rawMentions, body);
const data = await this.rpc("/mail/message/update_content", {
await this.rpc("/mail/message/update_content", {
attachment_ids: attachments
.map(({ id }) => id)
.concat(message.attachments.map(({ id }) => id)),
body: await prettifyMessageContent(body, validMentions),
message_id: message.id,
});
message.body = markup(data.body);
message.attachments.push(...attachments);
if (!message.isEmpty && this.store.hasLinkPreviewFeature) {
this.rpc(
"/mail/link_preview",
@@ -62,7 +59,7 @@ export class MessageService {
}
message.body = "";
message.attachments = [];
return this.rpc("/mail/message/update_content", {
await this.rpc("/mail/message/update_content", {
attachment_ids: [],
body: "",
message_id: message.id,
@@ -124,7 +124,7 @@ patch(MockServer.prototype, "mail/controllers/discuss", {
attachment_ids: this._mockIrAttachment_attachmentFormat(args.attachment_ids),
},
});
return args;
return "dummy value for mock server";
}
if (route === "/mail/read_subscription_data") {
const follower_id = args.follower_id;