summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/services/mail_manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/js/services/mail_manager.js')
-rw-r--r--addons/mail/static/src/js/services/mail_manager.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/services/mail_manager.js b/addons/mail/static/src/js/services/mail_manager.js
index 204a88bb8e9..5eb588d24e7 100644
--- a/addons/mail/static/src/js/services/mail_manager.js
+++ b/addons/mail/static/src/js/services/mail_manager.js
@@ -53,6 +53,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();
@@ -339,6 +345,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) {
@@ -919,6 +933,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.
*