[FIX] mail_bot: revert of notification request change

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) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2020-03-11 13:01:37 +00:00
parent cf42c2e27c
commit db6a018c84
2 changed files with 1 additions and 10 deletions
@@ -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();
}
},
//--------------------------------------------------------------------------
@@ -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();
},
/**