[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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user