From cf86759d1d3bd25cdb4cc7e750cbf9ae9ab8fbe5 Mon Sep 17 00:00:00 2001 From: zel-odoo Date: Thu, 2 Nov 2023 10:43:55 +0100 Subject: [PATCH] [FIX] mail: wrong use of group_based_subscription MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. `searchPartnerSuggestions` uses`authorizedGroupFullName` to see if the channel is public or not 2. `filteredThreads` and `getThreads` uses `hasSelfAsMember` and `is_pinned` along with the channel type 3. search should use `displayName` otherwise the search on group with default empty name will fail 4. fix tests. closes odoo/odoo#140495 X-original-commit: b358c410988686610638e7ffbee1fbbbeff5f0ba Signed-off-by: Sébastien Theys (seb) --- .../src/core/common/suggestion_service.js | 2 +- .../static/src/core/common/thread_model.js | 4 +++ .../static/src/core/web/messaging_menu.js | 2 +- .../core/web/discuss_sidebar_categories.js | 2 +- .../tests/discuss/core/suggestion_tests.js | 7 +++++- .../static/tests/discuss_app/sidebar_tests.js | 25 ++++++++++++------- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/addons/mail/static/src/core/common/suggestion_service.js b/addons/mail/static/src/core/common/suggestion_service.js index a5bfd9b4c51..a732a02d5af 100644 --- a/addons/mail/static/src/core/common/suggestion_service.js +++ b/addons/mail/static/src/core/common/suggestion_service.js @@ -100,7 +100,7 @@ export class SuggestionService { thread && (thread.type === "group" || thread.type === "chat" || - (thread.type === "channel" && thread.group_based_subscription)); + (thread.type === "channel" && thread.authorizedGroupFullName)); if (isNonPublicChannel) { // Only return the channel members when in the context of a // group restricted channel. Indeed, the message with the mention diff --git a/addons/mail/static/src/core/common/thread_model.js b/addons/mail/static/src/core/common/thread_model.js index 77f0c2491ba..e0ffb6874ae 100644 --- a/addons/mail/static/src/core/common/thread_model.js +++ b/addons/mail/static/src/core/common/thread_model.js @@ -324,6 +324,10 @@ export class Thread extends Record { return this.name; } + get displayToSelf() { + return this.is_pinned || (["channel", "group"].includes(this.type) && this.hasSelfAsMember); + } + /** @type {import("models").Persona[]} */ get correspondents() { return this.channelMembers diff --git a/addons/mail/static/src/core/web/messaging_menu.js b/addons/mail/static/src/core/web/messaging_menu.js index 67062e8a430..fb5547035c5 100644 --- a/addons/mail/static/src/core/web/messaging_menu.js +++ b/addons/mail/static/src/core/web/messaging_menu.js @@ -113,7 +113,7 @@ export class MessagingMenu extends Component { /** @type {import("@mail/core/common/thread_model").Thread[]} */ let threads = Object.values(this.store.Thread.records).filter( (thread) => - thread.is_pinned || + thread.displayToSelf || (thread.needactionMessages.length > 0 && thread.type !== "mailbox") ); const tab = this.store.discuss.activeTab; diff --git a/addons/mail/static/src/discuss/core/web/discuss_sidebar_categories.js b/addons/mail/static/src/discuss/core/web/discuss_sidebar_categories.js index 4bc09cb2559..e10546ba2c2 100644 --- a/addons/mail/static/src/discuss/core/web/discuss_sidebar_categories.js +++ b/addons/mail/static/src/discuss/core/web/discuss_sidebar_categories.js @@ -84,7 +84,7 @@ export class DiscussSidebarCategories extends Component { filteredThreads(category) { return category.threads.filter((thread) => { return ( - (thread.is_pinned || thread.group_based_subscription) && + thread.displayToSelf && (!this.state.quickSearchVal || cleanTerm(thread.name).includes(cleanTerm(this.state.quickSearchVal))) ); diff --git a/addons/mail/static/tests/discuss/core/suggestion_tests.js b/addons/mail/static/tests/discuss/core/suggestion_tests.js index 8388b61eb50..928ca48ef0a 100644 --- a/addons/mail/static/tests/discuss/core/suggestion_tests.js +++ b/addons/mail/static/tests/discuss/core/suggestion_tests.js @@ -78,7 +78,12 @@ QUnit.test("Sort partner suggestions by recent chats", async () => { { partner_id: partner_3 }, ]); pyEnv["discuss.channel"].create([ - { name: "General", channel_type: "channel" }, + { name: "General", channel_type: "channel", channel_member_ids: [ + Command.create({ partner_id: pyEnv.currentPartnerId }), + Command.create({ partner_id: partner_1 }), + Command.create({ partner_id: partner_2 }), + Command.create({ partner_id: partner_3 }), + ]}, { channel_member_ids: [ Command.create({ diff --git a/addons/mail/static/tests/discuss_app/sidebar_tests.js b/addons/mail/static/tests/discuss_app/sidebar_tests.js index dbd2f60ba56..1fce3fbec09 100644 --- a/addons/mail/static/tests/discuss_app/sidebar_tests.js +++ b/addons/mail/static/tests/discuss_app/sidebar_tests.js @@ -299,23 +299,30 @@ QUnit.test("sidebar: open channel and leave it", async (assert) => { assert.verifySteps(["action_unfollow"]); }); -QUnit.test("sidebar: unpin channel from bus", async () => { +QUnit.test("sidebar: unpin chat from bus", async () => { const pyEnv = await startServer(); - const channelId = pyEnv["discuss.channel"].create({ name: "General" }); + const partnerId = pyEnv["res.partner"].create({ name: "Demo" }); + const channelId = pyEnv["discuss.channel"].create({ + channel_member_ids: [ + Command.create({ partner_id: pyEnv.currentPartnerId }), + Command.create({ partner_id: partnerId }), + ], + channel_type: "chat", + }); const { openDiscuss } = await start(); openDiscuss(); - await contains(".o-mail-DiscussSidebarChannel", { text: "General" }); + await contains(".o-mail-DiscussSidebarChannel", { text: "Demo" }); - await click(".o-mail-DiscussSidebarChannel", { text: "General" }); - await contains(".o-mail-Composer-input[placeholder='Message #General…']"); - await contains(".o-mail-Discuss-threadName", { value: "General" }); + await click(".o-mail-DiscussSidebarChannel", { text: "Demo" }); + await contains(".o-mail-Composer-input[placeholder='Message Demo…']"); + await contains(".o-mail-Discuss-threadName", { value: "Demo" }); - // Simulate receiving a leave channel notification + // Simulate receiving a unpin chat notification // (e.g. from user interaction from another device or browser tab) pyEnv["bus.bus"]._sendone(pyEnv.currentPartner, "discuss.channel/unpin", { id: channelId }); - await contains(".o-mail-DiscussSidebarChannel", { count: 0, text: "General" }); + await contains(".o-mail-DiscussSidebarChannel", { count: 0, text: "Demo" }); - await contains(".o-mail-Discuss-threadName", { count: 0, value: "General" }); + await contains(".o-mail-Discuss-threadName", { count: 0, value: "Demo" }); }); QUnit.test("chat - channel should count unread message [REQUIRE FOCUS]", async () => {