summaryrefslogtreecommitdiff
path: root/addons/mail_bot/static/src/js/mailbot_service.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-08-30 16:10:20 +0200
committerAlexandre Kühn <aku@odoo.com>2018-08-30 17:55:18 +0200
commitf80bbb4b2a1230ba543e97d3da01c7b2c52d24cc (patch)
tree34d27fbdab943be7a2ebd675095060bb6ea512b5 /addons/mail_bot/static/src/js/mailbot_service.js
parentf8e3aed20ba073294fa1453f86709d6cbce650f5 (diff)
[IMP] mail, mail_bot: improved push notifications permission response
This commit makes small improvements on the messaging menu with the new module `mail_bot`: [IMP] When OdooBot has a request, it now adds "+1" to the counter of the messaging menu. The related preview also has a bold title, and displays "(1)" next to the title. [REF] Static previews are no longer in mail_service. This was only used for "OdooBot has a request" preview. This logic has now been moved to the module `mail_bot` (was previously in `mail`). [FIX] Title of response of push notifications permission clearly states whether permission has been granted or denied (was displaying "[Object object]" before this commit). Task-ID 1877502
Diffstat (limited to 'addons/mail_bot/static/src/js/mailbot_service.js')
-rw-r--r--addons/mail_bot/static/src/js/mailbot_service.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/addons/mail_bot/static/src/js/mailbot_service.js b/addons/mail_bot/static/src/js/mailbot_service.js
index 300e95d06db..a75780ab090 100644
--- a/addons/mail_bot/static/src/js/mailbot_service.js
+++ b/addons/mail_bot/static/src/js/mailbot_service.js
@@ -5,8 +5,9 @@ var AbstractService = require('web.AbstractService');
var core = require('web.core');
var session = require('web.session');
+var _t = core._t;
+
var MailBotService = AbstractService.extend({
- name: 'mailbot_service',
/**
* @override
*/
@@ -22,7 +23,40 @@ var MailBotService = AbstractService.extend({
}, 2*60*1000);
}
},
+ /**
+ * Get the previews related to the OdooBot (conversation not included).
+ * For instance, when there is no conversation with OdooBot and OdooBot has
+ * a request, it should display a preview in the systray messaging menu.
+ *
+ * @param {string|undefined} [filter]
+ * @returns {Object[]} list of objects that are compatible with the
+ * '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,
+ });
+ }
+ return previews;
+ },
+ /**
+ * Tell whether OdooBot has a request or not.
+ *
+ * @returns {boolean}
+ */
+ hasRequest: function () {
+ return window.Notification && window.Notification.permission === "default";
+ },
});
+
core.serviceRegistry.add('mailbot_service', MailBotService);
return MailBotService;
+
});