From 64f044761aa52bc4fb87821de415aef5a8fea0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 5 Dec 2018 14:35:09 +0000 Subject: [PATCH] [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 --- .../bus/static/src/js/services/bus_service.js | 2 +- .../static/src/img/odoobot_transparent.png | Bin 0 -> 4487 bytes .../mail_bot/static/src/js/mailbot_service.js | 32 +++++++++++------- .../static/src/js/systray_messaging_menu.js | 5 +-- .../tests/systray_messaging_menu_tests.js | 8 ++--- 5 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 addons/mail/static/src/img/odoobot_transparent.png 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 new file mode 100644 index 0000000000000000000000000000000000000000..e8c5a4dada888ad64758755c83d5da9293036510 GIT binary patch literal 4487 zcmY*dcRU+_nY7E%$zy%oaZ@b{+o%>)mEV(Wg!Is02FGfO8U2}*&ib&yqzV>QA~yCOwhkh`ZqIJf z0Dz1y_||oEK-vI(-CW%fVBf#E{ziar{Xbz47w~Tg(&aBMQ!QPfqKBsg@S(^95m7E# zQXmj0<7w{*)>l&gH~n_^7Z(hPdoM{xf`^1nPv4hTC>_%kH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TSH>a469L8(k z_}*z;J6~(mZuj094ib%%+-BB_oa?vE96k_TG7o4V!J7JcHb0_u3~u9LnGh(jldgAI zj($()H!H59UOQmB@#`ek1vCMHfqV%p6njnpbFjmL68wDp2i8En2M3W?_~E-N782O7UI%)>)Bc zqm&fIff?9#j)M1}UtYY`nKE3Oh2&^Of7Yjp+8OM3tR7-qg=*DFVPQk*y45BL3g-{) z%?Z|d=b(j#6_5NV&MtcbK4Zx^Ta(OPnKZ6ZjY+(ctOl%zmSmqG)w%wO03(HyH>DHjZ#ZTGk`UXHkFT4tj0s3C&#g}QHO0l_lcHA{YCV+xMqV+Xy)NzWSyg;w?yIbm(ar8G zGOXbwQ>fhTmKYG^>|$8eBF@%-s1IrKW+{yhtqx60NPD~pdMY$=L|8%>Z$5@y9kQ>~ z6%?&oV8?qf#l9OflLf)Z3RSNE4%KooKREyIcXJ5aEkV}}4n?7q2ShK!=g;qm+7oT1 JY6a`C{{iV`RagK3 literal 0 HcmV?d00001 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, {