diff --git a/addons/mail/static/src/web/messaging_menu/messaging_menu.js b/addons/mail/static/src/web/messaging_menu/messaging_menu.js index b126d3c3f5b..0b8c781d73c 100644 --- a/addons/mail/static/src/web/messaging_menu/messaging_menu.js +++ b/addons/mail/static/src/web/messaging_menu/messaging_menu.js @@ -114,6 +114,9 @@ export class MessagingMenu extends Component { threads = threads.filter(({ type }) => this.tabToThreadType(tab).includes(type)); } threads.sort((a, b) => { + if (a.correspondent === this.store.odoobot) { + return 1; + } if (!a.mostRecentNonTransientMessage?.datetime) { return -1; } diff --git a/addons/mail/static/src/web/messaging_service_patch.js b/addons/mail/static/src/web/messaging_service_patch.js index 7dd21712f54..e08999341cc 100644 --- a/addons/mail/static/src/web/messaging_service_patch.js +++ b/addons/mail/static/src/web/messaging_service_patch.js @@ -27,7 +27,9 @@ patch(Messaging.prototype, "mail/web", { async _handleNotificationNewMessage(notif) { await this._super(notif); const channel = this.store.threads[createLocalId("mail.channel", notif.payload.id)]; - this.chatWindowService.insert({ thread: channel }); + if (channel.correspondent !== this.store.odoobot) { + this.chatWindowService.insert({ thread: channel }); + } }, }); diff --git a/addons/mail/static/tests/chat_window/chat_window_tests.js b/addons/mail/static/tests/chat_window/chat_window_tests.js index 71c740774f5..8d699d47c89 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -651,6 +651,29 @@ QUnit.test("chat window should open when receiving a new DM", async (assert) => assert.containsOnce($, ".o-mail-ChatWindow"); }); +QUnit.test("chat window should not open when receiving a new DM from odoobot", async (assert) => { + const pyEnv = await startServer(); + const userId = pyEnv["res.users"].create({ partner_id: pyEnv.odoobotId }); + pyEnv["mail.channel"].create({ + channel_member_ids: [ + [0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }], + [0, 0, { partner_id: pyEnv.odoobotId }], + ], + channel_type: "chat", + uuid: "channel-uuid", + }); + const { env } = await start(); + // simulate receiving new message from odoobot + await afterNextRender(() => + env.services.rpc("/mail/chat_post", { + context: { mockedUserId: userId }, + message_content: "new message", + uuid: "channel-uuid", + }) + ); + assert.containsNone($, ".o-mail-ChatWindow"); +}); + QUnit.test( "chat window should scroll to the newly posted message just after posting it", async (assert) => {