From cecadbfb8f7e0f1b59c83838fac1e3abcd23ba39 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 14 Apr 2023 09:36:30 +0000 Subject: [PATCH] [FIX] im_livechat: fix message unread counter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since [1], the way the message unread counter is computed has changed. The patch of the `im_livechat` module is not adapted properly. This commit fixes this issue. [1]: 6ebe033b00774ed8824d05f0adf9dae5f3654261 closes odoo/odoo#118581 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/core/thread_service_patch.js | 2 +- .../static/tests/sidebar_patch_tests.js | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/im_livechat/static/src/core/thread_service_patch.js b/addons/im_livechat/static/src/core/thread_service_patch.js index b66bc7cfbdc..849b34e4a21 100644 --- a/addons/im_livechat/static/src/core/thread_service_patch.js +++ b/addons/im_livechat/static/src/core/thread_service_patch.js @@ -51,7 +51,7 @@ patch(ThreadService.prototype, "im_livechat", { getCounter(thread) { if (thread.type === "livechat") { - return thread.message_needaction_counter; + return thread.message_unread_counter; } return this._super(thread); }, diff --git a/addons/im_livechat/static/tests/sidebar_patch_tests.js b/addons/im_livechat/static/tests/sidebar_patch_tests.js index dd9f3fc7b58..f39d65901bc 100644 --- a/addons/im_livechat/static/tests/sidebar_patch_tests.js +++ b/addons/im_livechat/static/tests/sidebar_patch_tests.js @@ -449,3 +449,28 @@ QUnit.test("Clicking on unpin button unpins the channel", async (assert) => { await click(".o-mail-DiscussCategoryItem [title='Unpin Conversation']"); assert.verifySteps(["You unpinned your conversation with Visitor 11"]); }); + +QUnit.test("Message unread counter", async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ name: "Harry" }); + const userId = pyEnv["res.users"].create({ name: "Harry", partner_id: partnerId }); + const channelId = pyEnv["mail.channel"].create({ + anonymous_name: "Visitor 11", + channel_member_ids: [ + [0, 0, { partner_id: pyEnv.currentPartnerId }], + [0, 0, { partner_id: pyEnv.publicPartnerId }], + ], + channel_type: "livechat", + livechat_operator_id: pyEnv.currentPartnerId, + }); + const { env, openDiscuss } = await start(); + await openDiscuss(); + await afterNextRender(async () => + env.services.rpc("/mail/chat_post", { + context: { mockedUserId: userId }, + message_content: "hu", + uuid: pyEnv["mail.channel"].searchRead([["id", "=", channelId]])[0].uuid, + }) + ); + assert.containsOnce($, ".o-mail-DiscussCategoryItem .badge:contains(1)"); +});