Skip to content
Snippets Groups Projects
Commit b7254eca authored by jerome hanke (jhk)'s avatar jerome hanke (jhk) Committed by Nicolas Martinelli
Browse files

[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#45183

Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 870eb3fd
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
},
//--------------------------------------------------------------------------
......
......@@ -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();
},
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment