From 8acfad7a2ac8eb8d5beb2cee135608bf22df3e64 Mon Sep 17 00:00:00 2001 From: "Giorgio Tocco (gito)" Date: Wed, 13 Nov 2024 14:40:08 +0000 Subject: [PATCH] [FIX] mail: odoobot message remains unread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, messages sent by OdooBot would remain unread. 1. Log in as demo user 2. Open OdooBot chat, remains unread This happens because the `_set_last_seen_message` method called by the OdooBot reply logic sets the message as seen for the user. This results in the message being marked as read before it is received, preventing it to be marked as read by the client. This commit fixes the issue by preventing the message to be mark as read if the author is not the current user. Also added missing `message_unread_counter_bus_id` from `assignedDefined` that would prevent it to be set by record inserts. task-4295630 opw-4316799 closes odoo/odoo#188523 X-original-commit: abcc17cbc41543ee4121c94e81901f2ee4015c6a Signed-off-by: Alexandre Kühn (aku) --- addons/mail/models/discuss/discuss_channel.py | 4 ++-- addons/test_discuss_full/tests/test_performance.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/discuss/discuss_channel.py b/addons/mail/models/discuss/discuss_channel.py index 8804d728e9136..07f239ebd9b44 100644 --- a/addons/mail/models/discuss/discuss_channel.py +++ b/addons/mail/models/discuss/discuss_channel.py @@ -729,9 +729,9 @@ def _message_post_after_hook(self, message, msg_vals): """ Automatically set the message posted by the current user as seen for themselves. """ - if current_channel_member := self.env["discuss.channel.member"].search([ + if (current_channel_member := self.env["discuss.channel.member"].search([ ("channel_id", "=", self.id), ("is_self", "=", True) - ]): + ])) and message.is_current_user_or_guest_author: current_channel_member._set_last_seen_message(message, notify=False) current_channel_member._set_new_message_separator(message.id + 1, sync=True) return super()._message_post_after_hook(message, msg_vals) diff --git a/addons/test_discuss_full/tests/test_performance.py b/addons/test_discuss_full/tests/test_performance.py index 2f88b2a4b9654..05a2c31f8f55f 100644 --- a/addons/test_discuss_full/tests/test_performance.py +++ b/addons/test_discuss_full/tests/test_performance.py @@ -267,6 +267,9 @@ def setUp(self): author_id=self.users[2].partner_id.id, partner_ids=self.users[0].partner_id.ids, ) + members = self.channel_channel_public_1.channel_member_ids + member = members.filtered(lambda m: m.partner_id == self.users[0].partner_id).with_user(self.users[0]) + member._mark_as_read(message_0.id) # add star message_0.toggle_message_starred() self.env.company.sudo().name = 'YourCompany'