diff --git a/addons/bus/static/src/services/assets_watchdog_service.js b/addons/bus/static/src/services/assets_watchdog_service.js index bcff51bbf14..eba79b9dd99 100644 --- a/addons/bus/static/src/services/assets_watchdog_service.js +++ b/addons/bus/static/src/services/assets_watchdog_service.js @@ -11,7 +11,7 @@ export const assetsWatchdogService = { let isNotificationDisplayed = false; let bundleNotifTimerID = null; - bus_service.onNotification(onNotification.bind(this)); + bus_service.addEventListener('notification', onNotification.bind(this)); bus_service.startPolling(); /** @@ -63,9 +63,10 @@ export const assetsWatchdogService = { /** * Reacts to bus's notification * - * @param {Array} notifications: list of received notifications + * @param {CustomEvent} ev + * @param {Array} [ev.detail] list of received notifications */ - function onNotification(notifications) { + function onNotification({ detail: notifications }) { for (const { payload, type } of notifications) { if (type === 'bundle_changed') { if (payload.server_version !== session.server_version) { diff --git a/addons/bus/static/src/services/bus_service.js b/addons/bus/static/src/services/bus_service.js index 2c7dc9188b2..2030fd60b50 100644 --- a/addons/bus/static/src/services/bus_service.js +++ b/addons/bus/static/src/services/bus_service.js @@ -51,24 +51,6 @@ export class BusService extends CrossTab { } } - /** - * Register listeners on notifications received on this bus service - * - * @param {function} callback - */ - onNotification(callback) { - this.addEventListener('notification', ({ detail }) => callback(detail)); - } - - /** - * Unregister listeners on notifications received on this bus service. - * - * @param {function} callback - */ - offNotification(callback) { - this.removeEventListener('notification', callback); - } - //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- diff --git a/addons/bus/static/tests/bus_tests.js b/addons/bus/static/tests/bus_tests.js index da303f14c37..ef05c113fc1 100644 --- a/addons/bus/static/tests/bus_tests.js +++ b/addons/bus/static/tests/bus_tests.js @@ -46,7 +46,7 @@ QUnit.module('Bus', { } }, }); - env.services['bus_service'].onNotification(notifications => { + env.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => { assert.step('notification - ' + notifications.toString()); }); env.services['bus_service'].addChannel('lambda'); @@ -163,7 +163,7 @@ QUnit.module('Bus', { } } }); - masterEnv.services['bus_service'].onNotification(notifications => { + masterEnv.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => { assert.step('master - notification - ' + notifications.toString()); }); masterEnv.services['bus_service'].addChannel('lambda'); @@ -176,7 +176,7 @@ QUnit.module('Bus', { } } }); - slaveEnv.services['bus_service'].onNotification(notifications => { + slaveEnv.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => { assert.step('slave - notification - ' + notifications.toString()); }); slaveEnv.services['bus_service'].addChannel('lambda'); @@ -213,7 +213,7 @@ QUnit.module('Bus', { } }); - masterEnv.services['bus_service'].onNotification(notifications => { + masterEnv.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => { assert.step('master - notification - ' + notifications.toString()); }); masterEnv.services['bus_service'].addChannel('lambda'); @@ -239,7 +239,7 @@ QUnit.module('Bus', { } } }); - slaveEnv.services['bus_service'].onNotification(notifications => { + slaveEnv.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => { assert.step('slave - notification - ' + notifications.toString()); }); slaveEnv.services['bus_service'].addChannel('lambda'); 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 7a7ed64ab69..d54a4d2605e 100644 --- a/addons/calendar/static/src/js/services/calendar_notification_service.js +++ b/addons/calendar/static/src/js/services/calendar_notification_service.js @@ -12,7 +12,7 @@ export const calendarNotificationService = { let nextCalendarNotifTimeout = null; const displayedNotifications = new Set(); - bus_service.onNotification(notifications => { + bus_service.addEventListener('notification', ({ detail: notifications }) => { for (const { payload, type } of notifications) { if (type === "calendar.alarm") { displayCalendarNotification(payload); 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 b58006f50e7..c409e87598e 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,7 +7,7 @@ export const iapNotificationService = { dependencies: ["bus_service", "notification"], start(env, { bus_service, notification }) { - bus_service.onNotification(notifications => { + bus_service.addEventListener('notification', ({ detail: notifications }) => { for (const { payload, type } of notifications) { if (type === 'iap_notification') { if (payload.error_type == 'success') { diff --git a/addons/im_livechat/static/src/legacy/widgets/livechat_button.js b/addons/im_livechat/static/src/legacy/widgets/livechat_button.js index 3e00f16faa7..a274002d179 100644 --- a/addons/im_livechat/static/src/legacy/widgets/livechat_button.js +++ b/addons/im_livechat/static/src/legacy/widgets/livechat_button.js @@ -68,7 +68,7 @@ const LivechatButton = Widget.extend({ }); } } - this.call('bus_service', 'onNotification', this._onNotification.bind(this)); + this.call('bus_service', 'addEventListener', 'notification', this._onNotification.bind(this)); if (this.messaging.livechatButtonView.buttonBackgroundColor) { this.$el.css('background-color', this.messaging.livechatButtonView.buttonBackgroundColor); } @@ -417,9 +417,10 @@ const LivechatButton = Widget.extend({ }, /** * @private - * @param {Array[]} notifications + * @param {CustomEvent} ev + * @param {Array[]} [ev.detail] Notifications coming from the bus. */ - _onNotification(notifications) { + _onNotification({ detail: notifications }) { for (let notification of notifications) { this._handleNotification(notification); } diff --git a/addons/mail/static/src/models/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler.js index 8d343925017..c76c268616a 100644 --- a/addons/mail/static/src/models/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler.js @@ -16,7 +16,7 @@ registerModel({ identifyingFields: ['messaging'], lifecycleHooks: { _willDelete() { - this.env.services['bus_service'].offNotification(this._handleNotifications); + this.env.services['bus_service'].removeEventListener('notification', this._handleNotifications); this.env.services['bus_service'].stopPolling(); }, }, @@ -26,22 +26,23 @@ registerModel({ * the current users. This includes pinned channels for instance. */ start() { - this.env.services['bus_service'].onNotification(this._handleNotifications); + this.env.services['bus_service'].addEventListener('notification', this._handleNotifications); this.env.services['bus_service'].startPolling(); }, /** * @private - * @param {Object[]} notifications - * @param {Array|string} notifications[i][0] meta-data of the notification. - * @param {string} notifications[i][0][0] name of database this + * @param {CustomEvent} ev + * @param {Object[]} [ev.detail] Notifications coming from the bus. + * @param {Array|string} ev.detail[i][0] meta-data of the notification. + * @param {string} ev.detail[i][0][0] name of database this * notification comes from. - * @param {string} notifications[i][0][1] type of notification. - * @param {integer} notifications[i][0][2] usually id of related type + * @param {string} ev.detail[i][0][1] type of notification. + * @param {integer} ev.detail[i][0][2] usually id of related type * of notification. For instance, with `mail.channel`, this is the id * of the channel. - * @param {Object} notifications[i][1] payload of the notification + * @param {Object} ev.detail[i][1] payload of the notification */ - async _handleNotifications(notifications) { + async _handleNotifications({ detail: notifications }) { const channelsLeft = new Set( notifications .filter(notification => notification.type === 'mail.channel/leave') diff --git a/addons/snailmail_account/static/src/js/snailmail_account_notification_manager.js b/addons/snailmail_account/static/src/js/snailmail_account_notification_manager.js index 02c64454b36..3d4a93f3528 100644 --- a/addons/snailmail_account/static/src/js/snailmail_account_notification_manager.js +++ b/addons/snailmail_account/static/src/js/snailmail_account_notification_manager.js @@ -11,11 +11,11 @@ var SnailmailAccountNotificationManager = AbstractService.extend({ start: function () { this._super.apply(this, arguments); core.bus.on('web_client_ready', null, () => { - this.call('bus_service', 'onNotification', this._onNotification.bind(this)); + this.call('bus_service', 'addEventListener', 'notification', this._onNotification.bind(this)); }); }, - _onNotification: function(notifications) { + _onNotification: function({ detail: notifications }) { for (const { payload, type } of notifications) { if (type === "snailmail_invalid_address") { this.displayNotification({ title: payload.title, message: payload.message, type: 'danger' }); diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index 359d8d76d30..dd44314d636 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -353,9 +353,10 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa * - -> The fadeInOutDelay will be 200ms (600ms delay + 200ms * 2 fade in fade out) * * @private - * @param {Array[]} notifications structured as specified by the bus feature + * @param {CustomEvent} ev + * @param {Array[]} [ev.detail] notifications structured as specified by the bus feature */ - _onNotification: function (notifications) { + _onNotification: function ({ detail: notifications }) { var nextPageEvent = false; if (notifications && notifications.length !== 0) { notifications.forEach(function (notification) { @@ -943,7 +944,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa }, 2000); } - this.call('bus_service', 'onNotification', this._onNotification.bind(this)); + this.call('bus_service', 'addEventListener', 'notification', this._onNotification.bind(this)); } }, diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 67a48e05499..605ee89e3c9 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -380,7 +380,7 @@ const Wysiwyg = Widget.extend({ this._collaborationChannelName = channelName; Wysiwyg.activeCollaborationChannelNames.add(channelName); - this.call('bus_service', 'onNotification', notifications => { + this.call('bus_service', 'addEventListener', 'notification', ({ detail: notifications}) => { for (const { payload, type } of notifications) { if ( type === 'editor_collaboration' &&