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"];