From 8fad8e6a26c6dc45e80072efaf8a118be64417f1 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Mon, 20 Feb 2023 14:14:58 +0000 Subject: [PATCH] [FIX] mail: new messages not showing for unknown channel types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this PR, messages received on channels with unknown channel types weren't displayed on discuss. This was due to the fact that the sidebar computed its items based on the channel type. Steps to reproduce this issue: - Open one browser as mitchell admin (on the Discuss app). - Open one browser as marc demo (on the Discuss app). - Send a message from admin to demo. - Unpin the channel on the admin browser. - Refresh admin browser. - Send a message from demo to admin. - The message is not received on the admin browser. This PR fixes the issue by fetching channel data if the channel type is missing when receiving a new message. closes odoo/odoo#113377 X-original-commit: 3398aa8b10a1d9ad75552871e532f57ffcdd4a7f Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Stockbauer Matthieu (tsm) --- .../models/messaging_notification_handler.js | 2 +- .../helpers/mock_server/models/mail_thread.js | 17 +++---- .../mail/static/tests/helpers/test_utils.js | 11 ++++- .../components/discuss_tests.js | 46 +++++++++++++++++++ 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/addons/mail/static/src/models/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler.js index 6fca3dc4d3f..789470a1802 100644 --- a/addons/mail/static/src/models/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler.js @@ -287,7 +287,7 @@ Model({ // particular the case with the `uuid` field that is assumed // "required" by the rest of the code and is necessary for some // features such as chat windows. - if (!channel) { + if (!channel || !channel.channel_type) { const res = await this.messaging.models["Thread"].performRpcChannelInfo({ ids: [channelId], }); diff --git a/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js b/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js index 85137736168..809f03657a8 100644 --- a/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js +++ b/addons/mail/static/tests/helpers/mock_server/models/mail_thread.js @@ -232,14 +232,6 @@ patch(MockServer.prototype, "mail/models/mail_thread", { // members const channels = this.getRecords("mail.channel", [["id", "=", message.res_id]]); for (const channel of channels) { - notifications.push([ - channel, - "mail.channel/new_message", - { - id: channel.id, - message: messageFormat, - }, - ]); // notify update of last_interest_dt const now = datetime_to_str(new Date()); const members = this.getRecords("mail.channel.member", [ @@ -256,10 +248,19 @@ patch(MockServer.prototype, "mail/models/mail_thread", { "mail.channel/last_interest_dt_changed", { id: channel.id, + isServerPinned: member.is_pinned, last_interest_dt: member.last_interest_dt, }, ]); } + notifications.push([ + channel, + "mail.channel/new_message", + { + id: channel.id, + message: messageFormat, + }, + ]); } } this.pyEnv["bus.bus"]._sendmany(notifications); diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index 1e989adbb8b..ec3b84ae202 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -105,7 +105,16 @@ function getAfterEvent({ messagingBus }) { function getClick({ afterNextRender }) { return async function click(selector) { - await afterNextRender(() => document.querySelector(selector).click()); + await afterNextRender(() => { + if (typeof selector === "string") { + $(selector)[0].click(); + } else if (selector instanceof HTMLElement) { + selector.click(); + } else { + // jquery + selector[0].click(); + } + }); }; } diff --git a/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js index 1e5d837ed71..26448c85a50 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js @@ -4011,3 +4011,49 @@ QUnit.module("mail", {}, function () { ); }); }); + +QUnit.test("Message shows up even if channel data is incomplete", async function (assert) { + const { click, env, openDiscuss, pyEnv } = await start(); + await openDiscuss(); + const correspondentUserId = pyEnv["res.users"].create({ name: "Albert" }); + const correspondentPartnerId = pyEnv["res.partner"].create({ + name: "Albert", + user_ids: [correspondentUserId], + }); + const channelId = pyEnv["mail.channel"].create({ + channel_member_ids: [ + [ + 0, + 0, + { + is_pinned: true, + partner_id: pyEnv.currentPartnerId, + }, + ], + [0, 0, { partner_id: correspondentPartnerId }], + ], + channel_type: "chat", + }); + await env.services.rpc("/mail/channel/notify_typing", { + context: { + mockedPartnerId: correspondentPartnerId, + }, + is_typing: true, + channel_id: channelId, + }); + const [channel] = pyEnv["mail.channel"].searchRead([["id", "=", channelId]]); + await afterNextRender( + async () => + await env.services.rpc("/mail/chat_post", { + context: { + mockedUserId: correspondentUserId, + }, + message_content: "hello world", + uuid: channel.uuid, + }) + ); + await click( + ".o_DiscussSidebarView_categoryChat .o_DiscussSidebarCategoryItem:contains(Albert)" + ); + assert.containsOnce(document.body, ".o_MessageView:contains(hello world)"); +});