From 27b472e5ed5fac975fd150a195850fdbac7c502c Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Thu, 14 Jul 2022 11:16:22 +0000 Subject: [PATCH] [IMP] bus, *: remove obsolete web_client_ready when using bus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *: calendar, iap_mail. Now that the bus service is a wowl service, we don't need to wait for the webclient to be ready before using it. Indeed, the services now have the bus service as a dependency which means it will always be ready in time. This also showed that the rpc service was missing as a bus service dependency. It has been added. Some part of the code were also checking if the bus service was in `env.services`. Those calls have been removed as well since we now have the guarantee that it is. closes odoo/odoo#96002 Signed-off-by: Sébastien Theys (seb) --- .../src/services/assets_watchdog_service.js | 6 ++---- addons/bus/static/src/services/bus_service.js | 2 +- .../services/calendar_notification_service.js | 14 ++++++------- .../js/services/iap_notification_service.js | 20 +++++++++---------- addons/mail/static/src/models/messaging.js | 4 +--- .../models/messaging_notification_handler.js | 6 ++---- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/addons/bus/static/src/services/assets_watchdog_service.js b/addons/bus/static/src/services/assets_watchdog_service.js index 8b73f9a44e1..c6e0e6863ac 100644 --- a/addons/bus/static/src/services/assets_watchdog_service.js +++ b/addons/bus/static/src/services/assets_watchdog_service.js @@ -11,10 +11,8 @@ export const assetsWatchdogService = { let isNotificationDisplayed = false; let bundleNotifTimerID = null; - env.bus.on("WEB_CLIENT_READY", null, async () => { - bus_service.onNotification(this, onNotification); - bus_service.startPolling(); - }); + bus_service.onNotification(this, onNotification); + bus_service.startPolling(); /** * Displays one notification on user's screen when assets have changed diff --git a/addons/bus/static/src/services/bus_service.js b/addons/bus/static/src/services/bus_service.js index bd4b86920a0..21a328ccd72 100644 --- a/addons/bus/static/src/services/bus_service.js +++ b/addons/bus/static/src/services/bus_service.js @@ -113,7 +113,7 @@ export class BusService extends CrossTab { } export const busService = { - dependencies: ['notification'], + dependencies: ['notification', 'rpc'], start(env, services) { return new BusService(env, services); }, diff --git a/addons/calendar/static/src/js/services/calendar_notification_service.js b/addons/calendar/static/src/js/services/calendar_notification_service.js index de44fe1b787..244221653bc 100644 --- a/addons/calendar/static/src/js/services/calendar_notification_service.js +++ b/addons/calendar/static/src/js/services/calendar_notification_service.js @@ -12,16 +12,14 @@ export const calendarNotificationService = { let nextCalendarNotifTimeout = null; const displayedNotifications = new Set(); - env.bus.on("WEB_CLIENT_READY", null, async () => { - bus_service.onNotification(this, (notifications) => { - for (const { payload, type } of notifications) { - if (type === "calendar.alarm") { - displayCalendarNotification(payload); - } + bus_service.onNotification(this, (notifications) => { + for (const { payload, type } of notifications) { + if (type === "calendar.alarm") { + displayCalendarNotification(payload); } - }); - bus_service.startPolling(); + } }); + bus_service.startPolling(); /** * Displays the Calendar notification on user's screen diff --git a/addons/iap_mail/static/src/js/services/iap_notification_service.js b/addons/iap_mail/static/src/js/services/iap_notification_service.js index 9499cbd9052..d2a831e741b 100644 --- a/addons/iap_mail/static/src/js/services/iap_notification_service.js +++ b/addons/iap_mail/static/src/js/services/iap_notification_service.js @@ -7,20 +7,18 @@ export const iapNotificationService = { dependencies: ["bus_service", "notification"], start(env, { bus_service, notification }) { - env.bus.on("WEB_CLIENT_READY", null, async () => { - bus_service.onNotification(this, (notifications) => { - for (const { payload, type } of notifications) { - if (type === 'iap_notification') { - if (payload.error_type == 'success') { - displaySuccessIapNotification(payload); - } else if (payload.error_type == 'danger') { - displayFailureIapNotification(payload); - } + bus_service.onNotification(this, (notifications) => { + for (const { payload, type } of notifications) { + if (type === 'iap_notification') { + if (payload.error_type == 'success') { + displaySuccessIapNotification(payload); + } else if (payload.error_type == 'danger') { + displayFailureIapNotification(payload); } } - }); - bus_service.startPolling(); + } }); + bus_service.startPolling(); /** * Displays the IAP success notification on user's screen diff --git a/addons/mail/static/src/models/messaging.js b/addons/mail/static/src/models/messaging.js index 730805d4ed2..11d8c7ac5f4 100644 --- a/addons/mail/static/src/models/messaging.js +++ b/addons/mail/static/src/models/messaging.js @@ -18,9 +18,7 @@ registerModel({ odoo.__DEBUG__.messaging = this; }, _willDelete() { - if (this.env.services['bus_service']) { - this.env.services['bus_service'].off('window_focus', null, this._handleGlobalWindowFocus); - } + this.env.services['bus_service'].off('window_focus', null, this._handleGlobalWindowFocus); delete odoo.__DEBUG__.messaging; }, }, diff --git a/addons/mail/static/src/models/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler.js index c04a69afe47..e6fbbdbca80 100644 --- a/addons/mail/static/src/models/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler.js @@ -16,10 +16,8 @@ registerModel({ identifyingFields: ['messaging'], lifecycleHooks: { _willDelete() { - if (this.env.services['bus_service']) { - this.env.services['bus_service'].off('notification'); - this.env.services['bus_service'].stopPolling(); - } + this.env.services['bus_service'].off('notification'); + this.env.services['bus_service'].stopPolling(); }, }, recordMethods: {