[FIX] mail, im_livechat: do not overwrite tab title on embed live chat
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) <seb@odoo.com> Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit is contained in:
@@ -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/**',
|
||||
|
||||
@@ -18,16 +18,14 @@ export class OutOfFocusService {
|
||||
* @param {Partial<import("services").Services>} 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<import("services").Services>} services
|
||||
|
||||
@@ -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"];
|
||||
Reference in New Issue
Block a user