diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-12-17 14:23:24 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-12-17 15:10:35 +0000 |
| commit | a15c03e0bdea20e5cee0da90c738cab580ea5c0c (patch) | |
| tree | 40fa3142e8c68cc3a3ddded729584f7d4853387a /addons/mail_bot/static/src/js | |
| parent | 4fd15e82bcdb0e1503b8168112e797cf024828b7 (diff) | |
[FIX] mail_bot: hide Odoobot request when denied (Firefox)
Before this commit, the notification "Odoobot has a request" would
stay on screen even though the user blocked them in Firefox.
This case occurred when the user clicks on "Not Now", which tells the
browser that the push notifications should be blocked until the next
page reload.
This commit fixes this issue, so that the notification is removed
when clicking on "Not Now", in addition to cleaning tests related
to push notifications.
Task-ID 1918476
closes odoo/odoo#29584
Diffstat (limited to 'addons/mail_bot/static/src/js')
| -rw-r--r-- | addons/mail_bot/static/src/js/mailbot_service.js | 41 | ||||
| -rw-r--r-- | addons/mail_bot/static/src/js/systray_messaging_menu.js | 1 |
2 files changed, 33 insertions, 9 deletions
diff --git a/addons/mail_bot/static/src/js/mailbot_service.js b/addons/mail_bot/static/src/js/mailbot_service.js index a75780ab090..d27487305ae 100644 --- a/addons/mail_bot/static/src/js/mailbot_service.js +++ b/addons/mail_bot/static/src/js/mailbot_service.js @@ -12,17 +12,16 @@ var MailBotService = AbstractService.extend({ * @override */ start: function () { - var self = this; + this._hasRequest = (window.Notification && window.Notification.permission === "default") || false; if ('odoobot_initialized' in session && ! session.odoobot_initialized) { - setTimeout(function () { - session.odoobot_initialized = true; - self._rpc({ - model: 'mail.channel', - method: 'init_odoobot', - }); - }, 2*60*1000); + this._showOdoobotTimeout(); } }, + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + /** * Get the previews related to the OdooBot (conversation not included). * For instance, when there is no conversation with OdooBot and OdooBot has @@ -52,7 +51,31 @@ var MailBotService = AbstractService.extend({ * @returns {boolean} */ hasRequest: function () { - return window.Notification && window.Notification.permission === "default"; + return this._hasRequest; + }, + /** + * Called when user either accepts or refuses push notifications. + */ + removeRequest: function () { + this._hasRequest = false; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + */ + _showOdoobotTimeout: function () { + var self = this; + setTimeout(function () { + session.odoobot_initialized = true; + self._rpc({ + model: 'mail.channel', + method: 'init_odoobot', + }); + }, 2*60*1000); }, }); diff --git a/addons/mail_bot/static/src/js/systray_messaging_menu.js b/addons/mail_bot/static/src/js/systray_messaging_menu.js index 05c0ee54f24..2ef1fc56d93 100644 --- a/addons/mail_bot/static/src/js/systray_messaging_menu.js +++ b/addons/mail_bot/static/src/js/systray_messaging_menu.js @@ -56,6 +56,7 @@ return MessagingMenu.include({ * @param {string} value */ _handleResponseNotificationPermission: function (value) { + this.call('mailbot_service', 'removeRequest'); if (value !== 'granted') { this.call('bus_service', 'sendNotification', _t('Permission denied'), _t('Odoo will not have the permission to send native notifications on this device.')); |
