From 27cea9d84c13fc73735c388ab64386e26cfc0a0e Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Thu, 25 Apr 2024 11:04:45 +0200 Subject: [PATCH] [FIX] mail: remove duplicate code for needaction counter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This code is a duplicate of the mail.message/inbox notification (https://github.com/odoo/odoo/blob/17.0/addons/mail/static/src/core/web/mail_core_web_service.js#L43) resulting in the counter being incremented twice. closes odoo/odoo#163310 Signed-off-by: Sébastien Theys (seb) --- .../common/discuss_core_common_service.js | 15 ------- .../static/tests/discuss_app/inbox_tests.js | 40 +++++++++++++++++++ .../helpers/mock_server/models/mail_thread.js | 10 +++++ 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js b/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js index ae85a224cf0..5aef75849ec 100644 --- a/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js +++ b/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js @@ -263,21 +263,6 @@ export class DiscussCoreCommon { if (notif.id > this.store.initBusId) { channel.message_unread_counter++; } - if (message.isNeedaction) { - const inbox = this.store.discuss.inbox; - if (message.notIn(inbox.messages)) { - inbox.messages.push(message); - if (notif.id > this.store.initBusId) { - inbox.counter++; - } - } - if (message.notIn(channel.needactionMessages)) { - channel.needactionMessages.push(message); - if (notif.id > this.store.initBusId) { - channel.message_needaction_counter++; - } - } - } } } if ( diff --git a/addons/mail/static/tests/discuss_app/inbox_tests.js b/addons/mail/static/tests/discuss_app/inbox_tests.js index cf9f47e9c5e..32a5570920d 100644 --- a/addons/mail/static/tests/discuss_app/inbox_tests.js +++ b/addons/mail/static/tests/discuss_app/inbox_tests.js @@ -646,3 +646,43 @@ QUnit.test("emptying inbox doesn't display rainbow man in another thread", async // weak test, no guarantee that we waited long enough for the potential rainbow man to show await contains(".o_reward_rainbow", { count: 0 }); }); + +QUnit.test("Counter should be incremented by 1 when receiving a message with a mention in a channel", async () => { + const pyEnv = await startServer(); + const channelId = pyEnv["discuss.channel"].create({ name: "General" }); + const partnerId = pyEnv["res.partner"].create({ name: "Thread" }); + const partnerUserId = pyEnv["res.partner"].create({ name: "partner1" }); + const userId = pyEnv["res.users"].create({ partner_id: partnerUserId }); + const messageId = pyEnv["mail.message"].create({ + body: "not empty", + model: "res.partner", + needaction: true, + needaction_partner_ids: [pyEnv.currentPartnerId], + res_id: partnerId, + }); + pyEnv["mail.notification"].create([ + { + mail_message_id: messageId, + notification_type: "inbox", + res_partner_id: pyEnv.currentPartnerId, + }, + ]); + const { openDiscuss, env } = await start(); + await openDiscuss(); + await contains("button", { text: "Inbox", contains: [".badge", { text: "1" }] }); + const mention = [pyEnv.currentPartnerId]; + const mentionName = pyEnv.currentPartner.name; + pyEnv.withUser(userId, () => + env.services.rpc("/mail/message/post", { + post_data: { + body: `@${mentionName} mention`, + message_type: "comment", + partner_ids: mention, + subtype_xmlid: "mail.mt_comment", + }, + thread_id: channelId, + thread_model: "discuss.channel", + }) + ); + await contains("button", { text: "Inbox", contains: [".badge", { text: "2" }] }); +}); 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 ee459770fb8..b50b09a8140 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 @@ -365,6 +365,16 @@ patch(MockServer.prototype, { this._mockDiscussChannel_ChannelSeen(ids, message.id); } } + if (message.partner_ids) { + for (const partner_id of message.partner_ids) { + const [partner] = this.getRecords("res.partner", [["id", "=", partner_id]]); + notifications.push([ + partner, + "mail.message/inbox", + messageFormat + ]); + } + } } this.pyEnv["bus.bus"]._sendmany(notifications); },