[IMP] bus, mail, mail_bot: improved native notification

With this commit, no push notification is sent to user when
to acknowledge that he just has accepted them. Also, on native
push notifications, the Odoo Bot icon now has a transparent
background.

Task-ID 1881001
This commit is contained in:
Alexandre Kühn
2018-12-06 14:51:28 +00:00
parent f3bd34b870
commit 64f044761a
5 changed files with 26 additions and 21 deletions
@@ -80,7 +80,7 @@ var BusService = CrossTab.extend(ServicesMixin, {
* @param {function} [callback] if given callback will be called when user clicks on notification
*/
_sendNativeNotification: function (title, content, callback) {
var notification = new Notification(title, {body: content, icon: "/mail/static/src/img/odoobot.png"});
var notification = new Notification(title, {body: content, icon: "/mail/static/src/img/odoobot_transparent.png"});
notification.onclick = function () {
window.focus();
if (this.cancel) {
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

@@ -23,6 +23,11 @@ var MailBotService = AbstractService.extend({
}, 2*60*1000);
}
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* Get the previews related to the OdooBot (conversation not included).
* For instance, when there is no conversation with OdooBot and OdooBot has
@@ -33,25 +38,28 @@ var MailBotService = AbstractService.extend({
* 'mail.Preview' template.
*/
getPreviews: function (filter) {
var previews = [];
if (this.hasRequest() && (filter === 'mailbox_inbox' || !filter)) {
previews.push({
title: _t("OdooBot has a request"),
imageSRC: "/mail/static/src/img/odoobot.png",
status: 'bot',
body: _t("Enable desktop notifications to chat"),
id: 'request_notification',
unreadCounter: 1,
});
if (!this.isRequestingForNativeNotifications()) {
return [];
}
if (filter && filter !== 'mailbox_inbox') {
return [];
}
var previews = [{
title: _t("OdooBot has a request"),
imageSRC: "/mail/static/src/img/odoobot.png",
status: 'bot',
body: _t("Enable desktop notifications to chat"),
id: 'request_notification',
unreadCounter: 1,
}];
return previews;
},
/**
* Tell whether OdooBot has a request or not.
* Tell whether OdooBot is requesting to enable push notifications.
*
* @returns {boolean}
*/
hasRequest: function () {
isRequestingForNativeNotifications: function () {
return window.Notification && window.Notification.permission === "default";
},
});
@@ -22,7 +22,7 @@ return MessagingMenu.include({
*/
_computeCounter: function () {
var counter = this._super.apply(this, arguments);
if (this.call('mailbot_service', 'hasRequest')) {
if (this.call('mailbot_service', 'isRequestingForNativeNotifications')) {
counter++;
}
return counter;
@@ -59,9 +59,6 @@ return MessagingMenu.include({
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 {
this.call('bus_service', 'sendNotification', _t('Yay, push notifications are enabled!'),
_t('Odoo has now the permission to send you native notifications on this device.'));
}
this._updateCounter();
},
@@ -27,7 +27,7 @@ QUnit.module('MessagingMenu', {
// Patch mailbot_service so that it does do not do any RPC, and
// the detection of push notifications permissions can be simulated in
// the test cases. By default, shows 'OdooBot has a request'
this.hasMailbotRequest = true;
this.isMailbotRequesting = true;
testUtils.mock.patch(MailBotService, {
/**
* @override
@@ -37,8 +37,8 @@ QUnit.module('MessagingMenu', {
* @override
* @returns {boolean}
*/
hasRequest: function () {
return self.hasMailbotRequest;
isRequestingForNativeNotifications: function () {
return self.isMailbotRequesting;
},
});
@@ -82,7 +82,7 @@ QUnit.test('messaging menu widget: rendering with OdooBot has a request', functi
QUnit.test('messaging menu widget: rendering without OdooBot has a request', function (assert) {
assert.expect(3);
this.hasMailbotRequest = false;
this.isMailbotRequesting = false;
var messagingMenu = new MessagingMenu();
testUtils.mock.addMockEnvironment(messagingMenu, {