diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-12-05 14:35:09 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-12-06 14:51:28 +0000 |
| commit | 64f044761aa52bc4fb87821de415aef5a8fea0d9 (patch) | |
| tree | 6b3596121a89563951469c76f4003c8b823f772d | |
| parent | f3bd34b870ea63025213b9964c34c8ba38443a79 (diff) | |
[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
| -rw-r--r-- | addons/bus/static/src/js/services/bus_service.js | 2 | ||||
| -rw-r--r-- | addons/mail/static/src/img/odoobot_transparent.png | bin | 0 -> 4487 bytes | |||
| -rw-r--r-- | addons/mail_bot/static/src/js/mailbot_service.js | 32 | ||||
| -rw-r--r-- | addons/mail_bot/static/src/js/systray_messaging_menu.js | 5 | ||||
| -rw-r--r-- | addons/mail_bot/static/tests/systray_messaging_menu_tests.js | 8 |
5 files changed, 26 insertions, 21 deletions
diff --git a/addons/bus/static/src/js/services/bus_service.js b/addons/bus/static/src/js/services/bus_service.js index 72ba8c1531b..36eb496270f 100644 --- a/addons/bus/static/src/js/services/bus_service.js +++ b/addons/bus/static/src/js/services/bus_service.js @@ -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) { diff --git a/addons/mail/static/src/img/odoobot_transparent.png b/addons/mail/static/src/img/odoobot_transparent.png Binary files differnew file mode 100644 index 00000000000..e8c5a4dada8 --- /dev/null +++ b/addons/mail/static/src/img/odoobot_transparent.png diff --git a/addons/mail_bot/static/src/js/mailbot_service.js b/addons/mail_bot/static/src/js/mailbot_service.js index a75780ab090..8863ea94ba0 100644 --- a/addons/mail_bot/static/src/js/mailbot_service.js +++ b/addons/mail_bot/static/src/js/mailbot_service.js @@ -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"; }, }); 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 05c0ee54f24..f7e64ff751e 100644 --- a/addons/mail_bot/static/src/js/systray_messaging_menu.js +++ b/addons/mail_bot/static/src/js/systray_messaging_menu.js @@ -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(); }, diff --git a/addons/mail_bot/static/tests/systray_messaging_menu_tests.js b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js index c248871c2c9..88f5c161f66 100644 --- a/addons/mail_bot/static/tests/systray_messaging_menu_tests.js +++ b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js @@ -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, { |
