From 09ac15e2dda6f4796f44fe8bf90f94b8259d957d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 27 Apr 2023 16:54:26 +0000 Subject: [PATCH] [REF] mail: clean code for message update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/mail/controllers/thread.py | 5 ----- addons/mail/models/discuss/discuss_channel.py | 11 ----------- addons/mail/models/mail_thread.py | 12 +++++++----- addons/mail/static/src/core/message_service.js | 7 ++----- .../tests/helpers/mock_server/controllers/discuss.js | 2 +- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/addons/mail/controllers/thread.py b/addons/mail/controllers/thread.py index d63ea6751a9..5c0f1eb9c53 100644 --- a/addons/mail/controllers/thread.py +++ b/addons/mail/controllers/thread.py @@ -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(), - } diff --git a/addons/mail/models/discuss/discuss_channel.py b/addons/mail/models/discuss/discuss_channel.py index ccc62ba00f0..212385e3c09 100644 --- a/addons/mail/models/discuss/discuss_channel.py +++ b/addons/mail/models/discuss/discuss_channel.py @@ -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. """ diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 730d7db9ecc..82f9c500322 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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 diff --git a/addons/mail/static/src/core/message_service.js b/addons/mail/static/src/core/message_service.js index 151a038f208..e78d6ca2366 100644 --- a/addons/mail/static/src/core/message_service.js +++ b/addons/mail/static/src/core/message_service.js @@ -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, diff --git a/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js b/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js index fbf4d787682..96ec2cb3771 100644 --- a/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js +++ b/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js @@ -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;