From aa23a5a41de2a58e5d212539240508b4f94cb970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 30 Sep 2015 13:59:27 +0200 Subject: [PATCH] [IMP] bus: allow bus to restart polling on demand The problem was that the bus didn't listen to new channels when they were registered until the end of the current longpoll. This allows mail to manually restart the polling. --- addons/bus/static/src/js/bus.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/bus/static/src/js/bus.js b/addons/bus/static/src/js/bus.js index 3c828668308..b89f66a7c33 100644 --- a/addons/bus/static/src/js/bus.js +++ b/addons/bus/static/src/js/bus.js @@ -1,4 +1,5 @@ odoo.define('bus.bus', function (require) { +"use strict"; var session = require('web.session'); var Widget = require('web.Widget'); @@ -40,11 +41,15 @@ bus.Bus = Widget.extend({ var self = this; self.activated = true; var data = {'channels': self.channels, 'last': self.last, 'options' : self.options}; - session.rpc('/longpolling/poll', data, {shadow : true}).then(function(result) { + this.current_poll = $.Deferred(); + this.current_poll.then(function (result) { _.each(result, _.bind(self.on_notification, self)); if(!self.stop){ self.poll(); } + }); + session.rpc('/longpolling/poll', data, {shadow : true}).then(function(result) { + self.current_poll.resolve(result); }, function(unused, e) { // no error popup if request is interrupted or fails for any reason e.preventDefault(); @@ -58,6 +63,12 @@ bus.Bus = Widget.extend({ } this.trigger("notification", [notification.channel, notification.message]); }, + restart_poll: function () { + if (this.current_poll) { + this.current_poll.fail(); + } + this.poll(); + }, add_channel: function(channel){ if(!_.contains(this.channels, channel)){ this.channels.push(channel);