diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py index 7ce87f64871..c943f55c39b 100644 --- a/addons/im_livechat/__manifest__.py +++ b/addons/im_livechat/__manifest__.py @@ -133,6 +133,7 @@ Help your customers with this chat, and analyse their feedback. ('remove', 'web/static/tests/mock_server_tests.js'), ('remove', 'im_livechat/static/**'), 'im_livechat/static/tests/helpers/**', + ('remove', 'im_livechat/static/tests/helpers/**/web/**'), 'im_livechat/static/src/embed/**/*', ('remove', 'im_livechat/static/src/embed/external/**/*'), ], diff --git a/addons/im_livechat/static/src/core/messaging_service_patch.js b/addons/im_livechat/static/src/core/messaging_service_patch.js deleted file mode 100644 index 3db3aac949f..00000000000 --- a/addons/im_livechat/static/src/core/messaging_service_patch.js +++ /dev/null @@ -1,23 +0,0 @@ -/* @odoo-module */ - -import { Messaging } from "@mail/core/common/messaging_service"; - -import { patch } from "@web/core/utils/patch"; - -patch(Messaging.prototype, "im_livechat", { - initMessagingCallback(data) { - this._super(data); - if (data.current_user_settings?.is_discuss_sidebar_category_livechat_open) { - this.store.discuss.livechat.isOpen = true; - } - }, - _handleNotificationRecordInsert(notif) { - this._super(notif); - const { "res.users.settings": settings } = notif.payload; - if (settings) { - this.store.discuss.livechat.isOpen = - settings.is_discuss_sidebar_category_livechat_open ?? - this.store.discuss.livechat.isOpen; - } - }, -}); diff --git a/addons/im_livechat/static/src/core/web/livechat_core_web_service.js b/addons/im_livechat/static/src/core/web/livechat_core_web_service.js new file mode 100644 index 00000000000..6ded0c0c2eb --- /dev/null +++ b/addons/im_livechat/static/src/core/web/livechat_core_web_service.js @@ -0,0 +1,44 @@ +/* @odoo-module */ + +import { reactive } from "@odoo/owl"; + +import { registry } from "@web/core/registry"; + +export class LivechatCoreWeb { + constructor(env, services) { + Object.assign(this, { + busService: services.bus_service, + }); + /** @type {import("@mail/core/common/messaging_service").Messaging} */ + this.messagingService = services["mail.messaging"]; + /** @type {import("@mail/core/common/store_service").Store} */ + this.store = services["mail.store"]; + } + + setup() { + this.messagingService.isReady.then((data) => { + if (data.current_user_settings?.is_discuss_sidebar_category_livechat_open) { + this.store.discuss.livechat.isOpen = true; + } + this.busService.subscribe("mail.record/insert", (payload) => { + const { "res.users.settings": settings } = payload; + if (settings) { + this.store.discuss.livechat.isOpen = + settings.is_discuss_sidebar_category_livechat_open ?? + this.store.discuss.livechat.isOpen; + } + }); + }); + } +} + +export const livechatCoreWeb = { + dependencies: ["bus_service", "mail.messaging", "mail.store"], + start(env, services) { + const livechatCoreWeb = reactive(new LivechatCoreWeb(env, services)); + livechatCoreWeb.setup(); + return livechatCoreWeb; + }, +}; + +registry.category("services").add("im_livechat.core.web", livechatCoreWeb); diff --git a/addons/im_livechat/static/tests/helpers/core/web/setup_manager_patch.js b/addons/im_livechat/static/tests/helpers/core/web/setup_manager_patch.js new file mode 100644 index 00000000000..fa7334a8a88 --- /dev/null +++ b/addons/im_livechat/static/tests/helpers/core/web/setup_manager_patch.js @@ -0,0 +1,16 @@ +/* @odoo-module */ + +import { livechatCoreWeb } from "@im_livechat/core/web/livechat_core_web_service"; + +import { setupManager } from "@mail/../tests/helpers/webclient_setup"; + +import { patch } from "@web/core/utils/patch"; + +patch(setupManager, "im_livechat/core/web", { + setupServices(...args) { + return { + ...this._super(...args), + "im_livechat.core.web": livechatCoreWeb, + }; + }, +});