[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.
This commit is contained in:
Géry Debongnie
2015-10-01 14:00:18 +02:00
parent 729c1fbec1
commit aa23a5a41d
+12 -1
View File
@@ -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);