diff --git a/addons/mail/static/src/core/web/message_patch.js b/addons/mail/static/src/core/web/message_patch.js index 64ec5f961af..ee6f82e8925 100644 --- a/addons/mail/static/src/core/web/message_patch.js +++ b/addons/mail/static/src/core/web/message_patch.js @@ -35,16 +35,7 @@ patch(Message.prototype, "mail/core/web", { } }, openRecord() { - if (this.message.resModel === "discuss.channel") { - this.threadService.open(this.message.originThread); - } else { - this.action.doAction({ - type: "ir.actions.act_window", - res_id: this.message.resId, - res_model: this.message.resModel, - views: [[false, "form"]], - }); - } + this.threadService.open(this.message.originThread); }, /** diff --git a/addons/mail/static/src/core/web/thread_service_patch.js b/addons/mail/static/src/core/web/thread_service_patch.js index 8fe98c05b64..0f6a2e5f6ba 100644 --- a/addons/mail/static/src/core/web/thread_service_patch.js +++ b/addons/mail/static/src/core/web/thread_service_patch.js @@ -15,6 +15,7 @@ let nextId = 1; patch(ThreadService.prototype, "mail/core/web", { setup(env, services) { this._super(env, services); + this.action = services.action; /** @type {import("@mail/core/common/attachment_service").AttachmentService} */ this.attachmentService = services["mail.attachment"]; /** @type {import("@mail/core/web/activity_service").ActivityService} */ @@ -199,8 +200,22 @@ patch(ThreadService.prototype, "mail/core/web", { } }, open(thread, replaceNewMessageChatWindow) { - if (!this.store.discuss.isActive || this.ui.isSmall) { - this.chatWindowService.open(thread, replaceNewMessageChatWindow); + if (!this.store.discuss.isActive && !this.ui.isSmall) { + this._openChatWindow(thread, replaceNewMessageChatWindow); + return; + } + if (this.ui.isSmall && thread.model === "discuss.channel") { + this._openChatWindow(thread, replaceNewMessageChatWindow); + return; + } + if (thread.model !== "discuss.channel") { + this.action.doAction({ + type: "ir.actions.act_window", + res_id: thread.id, + res_model: thread.model, + views: [[false, "form"]], + }); + return; } this._super(thread, replaceNewMessageChatWindow); }, @@ -227,11 +242,24 @@ patch(ThreadService.prototype, "mail/core/web", { } this._super(...arguments); }, + _openChatWindow(thread, replaceNewMessageChatWindow) { + const chatWindow = this.chatWindowService.insert({ + folded: false, + thread, + replaceNewMessageChatWindow, + }); + chatWindow.autofocus++; + if (thread) { + thread.state = "open"; + } + this.chatWindowService.notifyState(chatWindow); + }, }); patch(threadService, "mail/core/web", { dependencies: [ ...threadService.dependencies, + "action", "mail.activity", "mail.attachment", "mail.chat_window", diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index 32daf48d37a..b1426ff3af4 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -1835,3 +1835,36 @@ QUnit.test( assert.strictEqual($(".o_breadcrumb").text(), "DiscussGeneral"); } ); + +QUnit.test( + "Chatter notification in messaging menu should open the form view even when discuss app is open", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ name: "TestPartner" }); + const messageId = pyEnv["mail.message"].create({ + model: "res.partner", + body: "A needaction message to have it in messaging menu", + author_id: pyEnv.odoobotId, + needaction: true, + needaction_partner_ids: [pyEnv.currentPartnerId], + res_id: partnerId, + }); + pyEnv["mail.notification"].create({ + mail_message_id: messageId, + notification_status: "sent", + notification_type: "inbox", + res_partner_id: pyEnv.currentPartnerId, + }); + const { openDiscuss } = await start(); + await openDiscuss(); + await click(".o_main_navbar i[aria-label='Messages']"); + await click(".o-mail-NotificationItem"); + assert.containsNone($, ".o-mail-Discuss"); + assert.containsOnce($, ".o_form_view .o-mail-Chatter"); + assert.containsOnce($, ".o_form_view .o_breadcrumb:contains(TestPartner)"); + assert.containsOnce( + $, + ".o-mail-Chatter .o-mail-Message:contains(A needaction message to have it in messaging menu)" + ); + } +);