[FIX] mail: remove duplicate code for needaction counter
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) <seb@odoo.com>
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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: `<a href="https://www.hoot.test/web#model=res.partner&id=17" class="o_mail_redirect" data-oe-id="${mention[0]}" data-oe-model="res.partner" target="_blank" contenteditable="false">@${mentionName}</a> 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" }] });
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user