From a1e87bbf236601dbeee4fcf0ab88cf0f19f4b136 Mon Sep 17 00:00:00 2001 From: "jerome hanke (jhk)" Date: Wed, 12 Feb 2020 11:51:40 +0000 Subject: [PATCH] [FIX] mail_bot: odoobot waits 1 week between notification requests Steps to reproduce: - install mail_bot - wait for odoobot to ask you if you want to receive notifications - do not select "grant" or "deny", click the closing cross Previous behavior: Odoobot would consider that you denied the request Current behavior: Odoobot waits 1 week and will ask you again opw-2186299 closes odoo/odoo#46697 X-original-commit: b7254ecaeee7f8fa564ca2059f119f5d12404af6 Signed-off-by: mightyjol --- addons/mail_bot/static/src/js/mailbot_service.js | 5 +++++ addons/mail_bot/static/src/js/systray_messaging_menu.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/mail_bot/static/src/js/mailbot_service.js b/addons/mail_bot/static/src/js/mailbot_service.js index 5312e5d5129..45d367f406d 100644 --- a/addons/mail_bot/static/src/js/mailbot_service.js +++ b/addons/mail_bot/static/src/js/mailbot_service.js @@ -4,6 +4,7 @@ odoo.define('mail_bot.MailBotService', function (require) { var AbstractService = require('web.AbstractService'); var core = require('web.core'); var session = require('web.session'); +var localStorage = require('web.local_storage'); var _t = core._t; @@ -13,9 +14,13 @@ var MailBotService = AbstractService.extend({ */ start: function () { this._hasRequest = (window.Notification && window.Notification.permission === "default") || false; + var lastRequestTime = localStorage.getItem('odoobot_notification_last_request_time'); if ('odoobot_initialized' in session && ! session.odoobot_initialized) { this._showOdoobotTimeout(); } + else if (lastRequestTime !== null && (new Date().getTime() - parseInt(lastRequestTime) > 7*24*60*60*1000)) { + this._showOdoobotTimeout(); + } }, //-------------------------------------------------------------------------- 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 f7bccee84ed..9839e2cc18f 100644 --- a/addons/mail_bot/static/src/js/systray_messaging_menu.js +++ b/addons/mail_bot/static/src/js/systray_messaging_menu.js @@ -57,10 +57,14 @@ return MessagingMenu.include({ */ _handleResponseNotificationPermission: function (value) { this.call('mailbot_service', 'removeRequest'); - if (value !== 'granted') { + localStorage.removeItem('odoobot_notification_last_request_time'); + if (value === 'denied') { this.call('bus_service', 'sendNotification', _t('Permission denied'), _t('Odoo will not have the permission to send native notifications on this device.')); } + else if (value === 'default') { + localStorage.setItem('odoobot_notification_last_request_time', new Date().getTime()); + } this._updateCounter(); }, /**