diff options
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/js/services/mail_manager.js | 33 | ||||
| -rw-r--r-- | addons/mail/static/src/js/systray/systray_messaging_menu.js | 72 |
2 files changed, 34 insertions, 71 deletions
diff --git a/addons/mail/static/src/js/services/mail_manager.js b/addons/mail/static/src/js/services/mail_manager.js index a9cbf7d1072..734f12f0cf3 100644 --- a/addons/mail/static/src/js/services/mail_manager.js +++ b/addons/mail/static/src/js/services/mail_manager.js @@ -46,7 +46,6 @@ var PREVIEW_MSG_MAX_SIZE = 350; // optimal for native english speakers var MailManager = AbstractService.extend({ dependencies: ['ajax', 'bus_service', 'local_storage'], _ODOOBOT_ID: "ODOOBOT", // default authorID for transient messages - IS_STATIC_PREVIEW_ENABLED: true, /** * @override @@ -232,17 +231,13 @@ var MailManager = AbstractService.extend({ var inboxDef = this._getSystrayInboxPreviews(filter); var failureDef = this._getSystrayMailFailurePreviews(filter); defs = defs.concat([channelDef, inboxDef, failureDef]); - if (this.IS_STATIC_PREVIEW_ENABLED) { - var staticDef = this._getSystrayStaticPreviews(filter); - defs.push(staticDef); - } return $.when.apply($, defs) - .then(function (previewsChannel, previewsInbox, previewsFailure, previewsStatic) { + .then(function (previewsChannel, previewsInbox, previewsFailure) { // order: failures > inbox > channel, each group must be sorted previewsChannel = self._sortPreviews(previewsChannel); previewsInbox = self._sortPreviews(previewsInbox); previewsFailure = self._sortPreviews(previewsFailure); - return _.union(previewsStatic, previewsFailure, previewsInbox, previewsChannel); + return _.union(previewsFailure, previewsInbox, previewsChannel); }); }, /** @@ -817,30 +812,6 @@ var MailManager = AbstractService.extend({ } }, /** - * Get the previews of static systray elements, adding notification request - * - * @private - * @param {string|undefined} [filter] - * @returns {$.Promise<Object[]>} resolved with list of object that are - * compatible with preview template of mail systray menu - */ - _getSystrayStaticPreviews: function (filter) { - var elems = []; - if ( - window.Notification && window.Notification.permission === "default" && - (filter === 'mailbox_inbox' || !filter) - ) { - elems.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', - }); - } - return $.when(elems); - }, - /** * Initialize the internal state of the mail service. Ensure that all * attributes are set before doing any operation on them. * diff --git a/addons/mail/static/src/js/systray/systray_messaging_menu.js b/addons/mail/static/src/js/systray/systray_messaging_menu.js index 4fc3e9a4940..5a687131504 100644 --- a/addons/mail/static/src/js/systray/systray_messaging_menu.js +++ b/addons/mail/static/src/js/systray/systray_messaging_menu.js @@ -7,8 +7,6 @@ var SystrayMenu = require('web.SystrayMenu'); var Widget = require('web.Widget'); var QWeb = core.qweb; -var _t = core._t; - /** * Menu item appended in the systray part of the navbar * @@ -92,6 +90,35 @@ var MessagingMenu = Widget.extend({ } }, /** + * Compute the counter next to the systray messaging menu. This counter is + * the sum of unread messages in channels, the counter of the mailbox inbox, + * and the amount of mail failures. + * + * @private + * @returns {integer} + */ + _computeCounter: function () { + var channels = this.call('mail_service', 'getChannels'); + var channelUnreadCounters = _.map(channels, function (channel) { + return channel.getUnreadCounter(); + }); + var unreadChannelCounter = _.reduce(channelUnreadCounters, function (c1, c2) { + return c1 + c2; + }, 0); + var inboxCounter = this.call('mail_service', 'getMailbox', 'inbox').getMailboxCounter(); + var mailFailureCounter = this.call('mail_service', 'getMailFailures').length; + + return unreadChannelCounter + inboxCounter + mailFailureCounter; + }, + /** + * @private + * @returns {$.Promise<Object[]>} resolved with list of previews that are + * compatible with the 'mail.Preview' template. + */ + _getPreviews: function () { + return this.call('mail_service', 'getSystrayPreviews', this._filter); + }, + /** * @private * @return {boolean} whether the messaging menu is shown or not. */ @@ -153,27 +180,6 @@ var MessagingMenu = Widget.extend({ })); }, /** - * Display the browser notification request dialog when the user clicks on systray's corresponding notification - * - * @private - */ - _requestNotificationPermission: function () { - var self = this; - var def = window.Notification && window.Notification.requestPermission(); - if (def) { - def.then(function (value) { - if (value !== 'granted') { - self.call('bus_service', 'sendNotification', self, _t('Permission denied'), - _t('Odoo will not have the permission to send native notifications on this device.')); - } else { - self.call('bus_service', 'sendNotification', self, _t('Permission granted'), - _t('Odoo has now the permission to send you native notifications on this device.')); - } - }); - } - this.$(".o_mail_navbar_request_permission").slideUp(); - }, - /** * Get and render list of previews, based on the selected filter * * preview shows the last message of a channel with inline format. @@ -200,7 +206,7 @@ var MessagingMenu = Widget.extend({ _updatePreviews: function () { // Display spinner while waiting for conversations preview this._$previews.html(QWeb.render('Spinner')); - this.call('mail_service', 'getSystrayPreviews', this._filter) + this._getPreviews() .then(this._renderPreviews.bind(this)); }, /** @@ -222,19 +228,7 @@ var MessagingMenu = Widget.extend({ * @private */ _updateCounter: function () { - var counter; - - var channels = this.call('mail_service', 'getChannels'); - var channelUnreadCounters = _.map(channels, function (channel) { - return channel.getUnreadCounter(); - }); - var unreadChannelCounter = _.reduce(channelUnreadCounters, function (c1, c2) { - return c1 + c2; - }, 0); - var inboxCounter = this.call('mail_service', 'getMailbox', 'inbox').getMailboxCounter(); - var mailFailureCounter = this.call('mail_service', 'getMailFailures').length; - - counter = unreadChannelCounter + inboxCounter + mailFailureCounter; + var counter = this._computeCounter(); this.$('.o_notification_counter').text(counter); this.$el.toggleClass('o_no_notification', !counter); if (this._isShown()) { @@ -289,8 +283,6 @@ var MessagingMenu = Widget.extend({ var documentID = $target.data('document-id'); var documentModel = $target.data('document-model'); this._openDocument(documentModel, documentID); - } else if (previewID === 'request_notification') { - this._requestNotificationPermission(); } else { // preview of thread this.call('mail_service', 'openThread', previewID); @@ -301,7 +293,7 @@ var MessagingMenu = Widget.extend({ * as read * * @private - * @param {MouseEvent} event + * @param {MouseEvent} ev */ _onClickPreviewMarkAsRead: function (ev) { ev.stopPropagation(); |
