From 8c249f33769528dbb241e4c7014bb85cb8b81dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 14 Jul 2023 18:07:43 +0000 Subject: [PATCH] [FIX] mail: chatter notif opens view even when discuss app is open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking on chatter notification from the messaging menu should either open chat window or form view, depending on whether the discuss app is closed or open respectively. Before this commit, when discuss app was open and user clicks on messaging menu item related to chatter notification, it was opening the chatter in discuss app. Although it works, some features seem missing, such as lack of chatter-specific features, and missing entry in the app sidebar. The discuss app is designed to work only on `discuss.channel` threads, therefore chatter threads should never be shown inside this app. This commit fixes the issue by ensuring that all opening of chatters from the discuss app opens the form view. closes odoo/odoo#128809 X-original-commit: 94c12dd231212e2e52b626a380344623c8627d7c Signed-off-by: Sébastien Theys (seb) Signed-off-by: Alexandre Kühn (aku) --- .../mail/static/src/core/web/message_patch.js | 11 +------ .../src/core/web/thread_service_patch.js | 32 ++++++++++++++++-- .../static/tests/discuss_app/discuss_tests.js | 33 +++++++++++++++++++ 3 files changed, 64 insertions(+), 12 deletions(-) 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)" + ); + } +);