diff options
Diffstat (limited to 'addons/mail/static/src')
3 files changed, 42 insertions, 60 deletions
diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js index 7db3474ebb2..a2316edb7be 100644 --- a/addons/mail/static/src/js/models/threads/channel.js +++ b/addons/mail/static/src/js/models/threads/channel.js @@ -387,24 +387,10 @@ var Channel = SearchableThread.extend(ChannelSeenMixin, ThreadTypingMixin, { */ _markAsRead: function () { var superDef = this._super.apply(this, arguments); - var seenDef = this._throttleNotifySeen(); + var seenDef = this._notifySeen(); return $.when(superDef, seenDef); }, /** - * @override {mail.model.ThreadSeenMixin} - * @private - * @returns {$.Promise} - */ - _notifyFetched: function () { - return this._rpc({ - model: 'mail.channel', - method: 'channel_fetched', - args: [[this._id]], - }, { - shadow: true - }); - }, - /** * @override {mail.model.ThreadTypingMixin} * @private * @param {Object} params @@ -420,25 +406,6 @@ var Channel = SearchableThread.extend(ChannelSeenMixin, ThreadTypingMixin, { }, { shadow: true }); }, /** - * @override {mail.model.ThreadSeenMixin} - * @private - * @returns {$.Promise<integer>} resolved with ID of last seen message - */ - _notifySeen: function () { - var self = this; - this._cancelThrottledNotifyFetched(); - return this._rpc({ - model: 'mail.channel', - method: 'channel_seen', - args: [[this._id]], - }, { - shadow: true - }).then(function (lastSeenMessageID) { - self._lastSeenMessageID = lastSeenMessageID; - return lastSeenMessageID; - }); - }, - /** * Prepare and send a message to the server on this channel. * * @override diff --git a/addons/mail/static/src/js/models/threads/mixins/channel_seen_mixin.js b/addons/mail/static/src/js/models/threads/mixins/channel_seen_mixin.js index 8a59db70aa2..022994673d2 100644 --- a/addons/mail/static/src/js/models/threads/mixins/channel_seen_mixin.js +++ b/addons/mail/static/src/js/models/threads/mixins/channel_seen_mixin.js @@ -1,8 +1,6 @@ odoo.define('mail.model.ChannelSeenMixin', function (require) { "use strict"; -var CCThrottleFunction = require('mail.model.CCThrottleFunction'); - var session = require('web.session'); /** @@ -25,12 +23,6 @@ var ChannelSeenMixin = { init: function (params) { this._seenPartnersInfo = params.data.seen_partners_info || []; - this._throttleNotifySeen = _.throttle(this._notifySeen.bind(this), 3000); - this._throttleNotifyFetched = CCThrottleFunction({ - duration: 3000, - func: this._notifyFetched.bind(this), - }); - this.on('message_added', this, this._onSeenMessageAdded); }, @@ -226,26 +218,18 @@ var ChannelSeenMixin = { /** * @private - */ - _cancelThrottledNotifyFetched: function () { - this._throttleNotifyFetched.cancel(); - this._throttleNotifyFetched.clear(); - }, - /** - * @abstract - * @private - * @returns {$.Promise} - */ - _notifyFetched: function () { - return $.when(); - }, - /** - * @abstract - * @private * @returns {$.Promise<integer>} resolved with ID of last seen message */ _notifySeen: function () { - return $.when(); + var self = this; + return this._rpc({ + model: 'mail.channel', + method: 'channel_seen', + args: [[this._id]], + }, { shadow: true }).then(function (lastSeenMessageID) { + self._lastSeenMessageID = lastSeenMessageID; + return lastSeenMessageID; + }); }, //-------------------------------------------------------------------------- @@ -256,7 +240,7 @@ var ChannelSeenMixin = { * @private */ _onSeenMessageAdded: function () { - this._throttleNotifyFetched(); + this.call('mail_service', 'notifyChannelFetched', { channelID: this._id }); }, }; diff --git a/addons/mail/static/src/js/services/mail_manager.js b/addons/mail/static/src/js/services/mail_manager.js index 6a49cdf0183..2234ce29af7 100644 --- a/addons/mail/static/src/js/services/mail_manager.js +++ b/addons/mail/static/src/js/services/mail_manager.js @@ -52,6 +52,12 @@ var MailManager = AbstractService.extend({ */ start: function () { this._super.apply(this, arguments); + + this._throttleNotifyChannelFetched = _.throttle(this._notifyChannelFetched.bind(this), 3000); + // List of channel that have requested the service to notify when + // it has been fetched, so that throttled RPCs batch the ids. + this._toNotifyChannelFetchedIDs = []; + this._initializeInternalState(); this._listenOnBuses(); this._fetchMailStateFromServer(); @@ -338,6 +344,14 @@ var MailManager = AbstractService.extend({ } }, /** + * @param {Object} data + * @param {integer} data.channelID + */ + notifyChannelFetched: function (data) { + this._toNotifyChannelFetchedIDs = _.uniq(this._toNotifyChannelFetchedIDs.concat(data.channelID)); + this._throttleNotifyChannelFetched(); + }, + /** * @param {integer|string} threadID */ openThread: function (threadID) { @@ -921,6 +935,23 @@ var MailManager = AbstractService.extend({ return new Message(this, data); }, /** + * @private + * @returns {$.Promise} + */ + _notifyChannelFetched: function () { + var channelIDs = this._toNotifyChannelFetchedIDs; + this._toNotifyChannelFetchedIDs = []; + if (_.isEmpty(channelIDs)) { + // no channel to notify fetched + return $.when(); + } + return this._rpc({ + model: 'mail.channel', + method: 'channel_fetched', + args: [channelIDs], + }, { shadow: true }); + }, + /** * shows a popup to notify a new received message. * This will also rename the browser tab if this is not the active tab. * |
