[FIX] bus, *: fix onNotification/offNotification
*: im_livechat, snailmail_account, survey, web_editor. The callback registered by the bus service method onNotification was not the same unregistered by offNotification. Since those method were superfluous, they have been removed in favor of (add/remove)EventListener. closes odoo/odoo#96684 Related: odoo/enterprise#29819 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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' });
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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' &&
|
||||
|
||||
Reference in New Issue
Block a user