From 60dc936be11e17eaced948da0c97655414fe5d2c Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 23 Feb 2024 08:45:02 +0100 Subject: [PATCH] [FIX] mail: fix missing identifying field in record insert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a message is posted, the server sends a `mail.record/insert` notification to update the related channel pin state. In order to recognize the thread, the client needs its id and its model. Currently, only the id is passed so the thread pin state is not updated. This PR adds the model to the notification. closes odoo/odoo#155150 Signed-off-by: Sébastien Theys (seb) --- addons/bus/static/tests/helpers/mock_server.js | 14 ++++++-------- addons/mail/models/discuss/discuss_channel.py | 4 +++- .../helpers/mock_server/models/mail_thread.js | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/bus/static/tests/helpers/mock_server.js b/addons/bus/static/tests/helpers/mock_server.js index 7302d55a25e..7667fe4b11f 100644 --- a/addons/bus/static/tests/helpers/mock_server.js +++ b/addons/bus/static/tests/helpers/mock_server.js @@ -118,15 +118,13 @@ patch(MockServer.prototype, { if (typeof target === "string") { return channel === target; } + if (Array.isArray(channel) !== Array.isArray(target)) { + return false; + } if (Array.isArray(channel)) { - const { __model: cModel, id: cId } = channel; - const { __model: tModel, id: tId } = target; - return ( - Array.isArray(target) && - cModel === tModel && - cId === tId && - channel[1] === target[1] - ); + const { __model: cModel, id: cId } = channel[0]; + const { __model: tModel, id: tId } = target[0]; + return cModel === tModel && cId === tId && channel[1] === target[1]; } return channel?.__model === target.__model && channel?.id === target?.id; }) diff --git a/addons/mail/models/discuss/discuss_channel.py b/addons/mail/models/discuss/discuss_channel.py index 42503e08a34..9f0ebaa956d 100644 --- a/addons/mail/models/discuss/discuss_channel.py +++ b/addons/mail/models/discuss/discuss_channel.py @@ -583,7 +583,9 @@ class Channel(models.Model): # notification of the message itself to ensure the channel automatically opens. payload = {"id": self.id, "last_interest_dt": fields.Datetime.now()} bus_notifications = [ - ((self, "members"), "mail.record/insert", {"Thread": {"id": self.id, "is_pinned": True}}), + ((self, "members"), "mail.record/insert", { + "Thread": {"id": self.id, "is_pinned": True, "model": "discuss.channel"} + }), (self, "discuss.channel/last_interest_dt_changed", payload), (self, "discuss.channel/new_message", {"id": self.id, "message": message_format}), ] diff --git a/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js b/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js index 8fea8010a77..ee459770fb8 100644 --- a/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js +++ b/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js @@ -341,6 +341,7 @@ patch(MockServer.prototype, { Thread: { id: channel.id, is_pinned: true, + model: "discuss.channel", }, }, ]);