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)"); +});