From 225cfc03f62f26ec8f15f2f86249b707f926f894 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Tue, 19 Dec 2023 09:54:04 +0100 Subject: [PATCH] [FIX] mail, im_livechat: do not overwrite tab title on embed live chat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since [1], messages received out of focus are notified to the user via the tab title. In order to do so, the title service is used. This service changes the tab title according to its internal state. When the live chat is embed on a page, the original title of the page is not coming from the title service. When the service state changes, the title is replaced without taking into account the original title. This behavior is not correct. In practice, this functionality is only used by the `web` bundle. The error occurs because the code handling this behavior is placed in the common bundle while it should not. This PR fixes this issue by moving this code to the `web` bundle. task-3644431 [1]: https://github.com/odoo/odoo/pull/145216 closes odoo/odoo#146752 X-original-commit: 43b67c377b6a236cb009b21afd62d8c593ef9cd6 Signed-off-by: Sébastien Theys (seb) Signed-off-by: Matthieu Stockbauer (tsm) --- addons/im_livechat/__manifest__.py | 1 + .../src/core/common/out_of_focus_service.js | 16 ++++-------- .../core/web/out_of_focus_service_patch.js | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 addons/mail/static/src/core/web/out_of_focus_service_patch.js diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py index 8966d6788bb..be340ea9000 100644 --- a/addons/im_livechat/__manifest__.py +++ b/addons/im_livechat/__manifest__.py @@ -92,6 +92,7 @@ Help your customers with this chat, and analyse their feedback. 'im_livechat.assets_embed_core': [ 'web/static/lib/odoo_ui_icons/style.css', 'web/static/src/scss/ui.scss', + ('remove', 'web/static/src/core/browser/title_service.js'), 'mail/static/src/core/common/**/*', 'mail/static/src/discuss/core/common/*', 'mail/static/src/discuss/call/common/**', diff --git a/addons/mail/static/src/core/common/out_of_focus_service.js b/addons/mail/static/src/core/common/out_of_focus_service.js index 40c57623ea1..66780ff1b44 100644 --- a/addons/mail/static/src/core/common/out_of_focus_service.js +++ b/addons/mail/static/src/core/common/out_of_focus_service.js @@ -18,16 +18,14 @@ export class OutOfFocusService { * @param {Partial} services */ constructor(env, services) { + this.setup(env, services); + } + + setup(env, services) { this.env = env; this.audio = undefined; - this.counter = 0; this.multiTab = services.multi_tab; this.notificationService = services.notification; - this.titleService = services.title; - env.bus.addEventListener("window_focus", () => { - this.counter = 0; - this.titleService.setParts({ _chat: undefined }); - }); } async notify(message, channel) { @@ -61,10 +59,6 @@ export class OutOfFocusService { title: notificationTitle, type: "info", }); - this.counter++; - this.titleService.setParts({ - _chat: this.counter === 1 ? _t("1 Message") : _t("%s Messages", this.counter), - }); } async hasServiceWorkInstalledAndPushSubscriptionActive() { @@ -165,7 +159,7 @@ export class OutOfFocusService { } export const outOfFocusService = { - dependencies: ["multi_tab", "notification", "title"], + dependencies: ["multi_tab", "notification"], /** * @param {import("@web/env").OdooEnv} env * @param {Partial} services diff --git a/addons/mail/static/src/core/web/out_of_focus_service_patch.js b/addons/mail/static/src/core/web/out_of_focus_service_patch.js new file mode 100644 index 00000000000..d38b1ecc541 --- /dev/null +++ b/addons/mail/static/src/core/web/out_of_focus_service_patch.js @@ -0,0 +1,25 @@ +/* @odoo-module */ + +import { OutOfFocusService, outOfFocusService } from "@mail/core/common/out_of_focus_service"; +import { patch } from "@web/core/utils/patch"; +import { _t } from "@web/core/l10n/translation"; +import { sprintf } from "@web/core/utils/strings"; + +patch(OutOfFocusService.prototype, { + setup(env, services) { + super.setup(env, services); + this.titleService = services.title; + this.counter = 0; + env.bus.addEventListener("window_focus", () => { + this.counter = 0; + this.titleService.setParts({ _chat: undefined }); + }); + }, + notify() { + super.notify(...arguments); + this.counter++; + const titlePattern = this.counter === 1 ? _t("%s Message") : _t("%s Messages"); + this.titleService.setParts({ _chat: sprintf(titlePattern, this.counter) }); + }, +}); +outOfFocusService.dependencies = [...outOfFocusService.dependencies, "title"];