From cdf456ea0005f162a7d40884ad4f6a502de28e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 24 Apr 2023 16:22:18 +0000 Subject: [PATCH] [FIX] mail: properly handle discuss active_id 'discuss.channel_' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when loading discuss app with `active_id=discuss.channel_1` in URL, the discuss app did not auto-select the conversation. This happens because the code did not parse model and id part of "discuss.channel_1": it split into `discuss.chann` and `l_1`, instead of `discuss.channel` and `1`. This comes from splitting the same way as legacy `mail.channel`, starts with 13 characters, although there are now 16 characters in `discuss.channel`. This commit fixes the issue by simplify the way the active thread of discuss is deduced from active_id. closes odoo/odoo#119559 Signed-off-by: Sébastien Theys (seb) --- .../mail/static/src/core/messaging_service.js | 22 ++++++------------- addons/mail/static/src/core/store_service.js | 4 +--- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/addons/mail/static/src/core/messaging_service.js b/addons/mail/static/src/core/messaging_service.js index 24e75229da4..77b9ae65884 100644 --- a/addons/mail/static/src/core/messaging_service.js +++ b/addons/mail/static/src/core/messaging_service.js @@ -759,22 +759,14 @@ export const messagingService = { start(env, services) { // compute initial discuss thread if not on public page if (!services["mail.store"].inPublicPage) { - let threadLocalId = createLocalId("mail.box", "inbox"); - const activeId = services.router.current.hash.active_id; - if (typeof activeId === "number") { - threadLocalId = createLocalId("discuss.channel", activeId); + const activeId = services.router.current.hash.active_id ?? "mail.box_inbox"; + let [model, id] = + typeof activeId === "number" ? ["discuss.channel", activeId] : activeId.split("_"); + if (model === "mail.channel") { + // legacy format (sent in old emails, shared links, ...) + model = "discuss.channel"; } - if (typeof activeId === "string" && activeId.startsWith("mail.box_")) { - threadLocalId = createLocalId("mail.box", activeId.slice(9)); - } - // legacy format (sent in old emails, shared links, ...) - if (typeof activeId === "string" && activeId.startsWith("mail.channel_")) { - threadLocalId = createLocalId("discuss.channel", parseInt(activeId.slice(13), 10)); - } - if (typeof activeId === "string" && activeId.startsWith("discuss.channel_")) { - threadLocalId = createLocalId("discuss.channel", parseInt(activeId.slice(13), 10)); - } - services["mail.store"].discuss.threadLocalId = threadLocalId; + services["mail.store"].discuss.threadLocalId = createLocalId(model, id); } const messaging = new Messaging(env, services); messaging.initialize(); diff --git a/addons/mail/static/src/core/store_service.js b/addons/mail/static/src/core/store_service.js index 44a4be149d2..f54ed42007b 100644 --- a/addons/mail/static/src/core/store_service.js +++ b/addons/mail/static/src/core/store_service.js @@ -155,9 +155,7 @@ export const storeService = { if (!res.isSmall) { res.discuss.activeTab = "all"; } else { - res.discuss.activeTab = res.discuss.threadLocalId - ? res.threads[res.discuss.threadLocalId].type - : "all"; + res.discuss.activeTab = res.threads[res.discuss.threadLocalId]?.type ?? "all"; } }); return res;