diff --git a/addons/mail/static/src/web/messaging_service_patch.js b/addons/mail/static/src/web/messaging_service_patch.js index 6c94371c93c..8289ccb2118 100644 --- a/addons/mail/static/src/web/messaging_service_patch.js +++ b/addons/mail/static/src/web/messaging_service_patch.js @@ -27,7 +27,12 @@ patch(Messaging.prototype, "mail/web", { async _handleNotificationNewMessage(notif) { await this._super(notif); const channel = this.store.threads[createLocalId("discuss.channel", notif.payload.id)]; - if (!this.store.isSmall && channel.correspondent !== this.store.odoobot) { + const message = this.store.messages[notif.payload.message.id]; + if ( + !this.store.isSmall && + channel.correspondent !== this.store.odoobot && + !message.isSelfAuthored + ) { this.chatWindowService.insert({ thread: channel }); } }, diff --git a/addons/mail/static/tests/messaging/messaging_tests.js b/addons/mail/static/tests/messaging/messaging_tests.js index b35c85d34f5..db2690345d8 100644 --- a/addons/mail/static/tests/messaging/messaging_tests.js +++ b/addons/mail/static/tests/messaging/messaging_tests.js @@ -1,13 +1,19 @@ /** @odoo-module **/ -import { afterNextRender, start } from "@mail/../tests/helpers/test_utils"; +import { + afterNextRender, + click, + insertText, + start, + startServer, +} from "@mail/../tests/helpers/test_utils"; QUnit.module("messaging"); QUnit.test( - "Posting a message to a partner out of discuss should open a chat window", + "Receiving a new message out of discuss app should open a chat window", async (assert) => { - const { env, pyEnv } = await start(); + const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Dumbledore" }); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); const channelId = pyEnv["discuss.channel"].create({ @@ -17,6 +23,8 @@ QUnit.test( ], channel_type: "chat", }); + const { env } = await start(); + // simulate receving new message await afterNextRender(() => env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, @@ -30,10 +38,9 @@ QUnit.test( ); QUnit.test( - "Posting a message to a partner should open a chat window after leaving discuss", + "Receiving a new message in discuss app should open a chat window after leaving discuss app", async (assert) => { - const { env, openDiscuss, openFormView, pyEnv } = await start(); - await openDiscuss(); + const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Dumbledore" }); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); const channelId = pyEnv["discuss.channel"].create({ @@ -43,6 +50,9 @@ QUnit.test( ], channel_type: "chat", }); + const { env, openDiscuss, openFormView } = await start(); + await openDiscuss(); + // simulate receiving new message env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, post_data: { body: "new message", message_type: "comment" }, @@ -54,3 +64,25 @@ QUnit.test( assert.containsOnce($, ".o-mail-ChatWindow-header:contains(Dumbledore)"); } ); + +QUnit.test( + "Posting a message in discuss app should not open a chat window after leaving discuss app", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ name: "Dumbledore" }); + const channelId = pyEnv["discuss.channel"].create({ + channel_member_ids: [ + [0, 0, { partner_id: pyEnv.currentPartnerId }], + [0, 0, { partner_id: partnerId }], + ], + channel_type: "chat", + }); + const { openDiscuss, openFormView } = await start(); + await openDiscuss(channelId); + await insertText(".o-mail-Composer-input", "test https://www.odoo.com/"); + await click(".o-mail-Composer-send"); + // leaving discuss. + await openFormView("res.partner", partnerId); + assert.containsNone($, ".o-mail-ChatWindow-header:contains(Dumbledore)"); + } +);