From db6a018c84468b80e1c32bca84fe743c874cdf26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 10 Mar 2020 15:42:35 +0000 Subject: [PATCH] [FIX] mail_bot: revert of notification request change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit [1] does not work as it is supposed to, because there has been a confusion between the "notification request" and the "chat with OdooBot". `_showOdoobotTimeout` is for the chat, and it is unrelated to the notification request. We don't want to initiate multiple chats with OdooBot so that has to be reverted. As for the original goal of the PR about the notification request, it wasn't met either because it is the browser controlling it: - on Firefox there simply isn't a "close" button, and closing it by any other means (escape key) is considered as a denied. - on Chrome, when closing it for the first time, it will appear again automatically after the next page reload, so no additional code is required. However, if it is closed too many times (around 3) it will become automatically denied too, at the browser level. The only thing to do at that point is to better notify the user that it was blocked, without being intrusive, which is the focus of task-2188584. [1] b7254ecaeee7f8fa564ca2059f119f5d12404af6 opw-2186299 closes odoo/odoo#47395 X-original-commit: 50155e808c44121086cc7436cec0e7f166cd4268 Signed-off-by: Sébastien Theys (seb) --- addons/mail_bot/static/src/js/mailbot_service.js | 5 ----- addons/mail_bot/static/src/js/systray_messaging_menu.js | 6 +----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/addons/mail_bot/static/src/js/mailbot_service.js b/addons/mail_bot/static/src/js/mailbot_service.js index 45d367f406d..5312e5d5129 100644 --- a/addons/mail_bot/static/src/js/mailbot_service.js +++ b/addons/mail_bot/static/src/js/mailbot_service.js @@ -4,7 +4,6 @@ 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; @@ -14,13 +13,9 @@ 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 9839e2cc18f..f7bccee84ed 100644 --- a/addons/mail_bot/static/src/js/systray_messaging_menu.js +++ b/addons/mail_bot/static/src/js/systray_messaging_menu.js @@ -57,14 +57,10 @@ return MessagingMenu.include({ */ _handleResponseNotificationPermission: function (value) { this.call('mailbot_service', 'removeRequest'); - localStorage.removeItem('odoobot_notification_last_request_time'); - if (value === 'denied') { + 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.')); } - else if (value === 'default') { - localStorage.setItem('odoobot_notification_last_request_time', new Date().getTime()); - } this._updateCounter(); }, /**