[FIX] bus,im_support: adapt im_support to bus changes

The im_support module was broken in 12.0 after bus refactorings between
11.0 and 12.0.

closes odoo/odoo#38838

X-original-commit: db37e0cedcd0da46bd57686a076a8165e60d6c3b
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Co-authored-by: @alexkuhn
This commit is contained in:
Olivier Dony
2019-10-15 17:43:19 +00:00
committed by fw-bot
co-authored by @alexkuhn
parent 607085166d
commit ae82f17cc9
4 changed files with 43 additions and 25 deletions
+10 -1
View File
@@ -182,7 +182,7 @@ var LongpollingBus = Bus.extend(ServicesMixin, {
});
var data = {channels: this._channels, last: this._lastNotificationID, options: options};
// The backend has a maximum cycle time of 50 seconds so give +10 seconds
this._pollRpc = this._rpc({route: this.POLL_ROUTE, params: data}, {shadow : true, timeout: 60000});
this._pollRpc = this._makePoll(data);
this._pollRpc.then(function (result) {
self._pollRpc = false;
self._onPoll(result);
@@ -199,6 +199,15 @@ var LongpollingBus = Bus.extend(ServicesMixin, {
}
});
},
/**
* @private
* @param data: object with poll parameters
*/
_makePoll: function(data) {
return this._rpc({route: this.POLL_ROUTE, params: data}, {shadow : true, timeout: 60000});
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
@@ -13,8 +13,12 @@ var core = require('web.core');
var SupportBusService = BusService.extend({
LOCAL_STORAGE_PREFIX: 'im_support',
POLL_ROUTE: '/longpolling/support_poll',
getSession: function () {
return supportSession;
/**
* @override _makePoll to force the remote session
*/
_makePoll: function(data) {
return supportSession.rpc(this.POLL_ROUTE, data, {shadow : true, timeout: 60000});
},
});
@@ -213,37 +213,41 @@ var SupportChannel = SearchableThread.extend({
* @override
* @private
*/
_fetchMessages: function (channel, options) {
_fetchMessages: function (pDomain, loadMore) {
var self = this;
var domain = options && options.domain || [];
var cache = this._getCache(channel, domain);
if (options && options.loadMore) {
var minMessageID = cache.messages[0].id;
var domain = [];
var cache = this._getCache(pDomain);
if (pDomain) {
domain = domain.concat(pDomain || []);
}
if (loadMore) {
// ignore the welcome message (ID==-1)
var msgs = cache.messages.filter(function(m) {return m.getID() !== -1});
var minMessageID = msgs[0].getID();
domain = [['id', '<', minMessageID]].concat(domain);
}
return supportSession.rpc('/odoo_im_support/fetch_messages', {
domain: domain,
channel_uuid: session.support_token,
limit: self._FETCH_LIMIT,
}).then(function (msgs) {
if (!cache.all_history_loaded) {
cache.all_history_loaded = msgs.length < self._FETCH_LIMIT;
}
cache.loaded = true;
_.each(msgs, function (msg) {
_.extend(msg, {channel_ids: [self.getID()]});
self.call('mail_service', 'addMessage', msg, {
channel_id: self.getID(),
silent: true,
domain: domain,
});
}).then(function (messages) {
if (!cache.allHistoryLoaded) {
cache.allHistoryLoaded = messages.length < self._FETCH_LIMIT;
}
cache.loaded = true;
_.each(messages, function (message) {
message.channel_ids = [self.getID()];
message.channel_id = self.getID();
self.call('mail_service', 'addMessage', message, {
silent: true,
domain: pDomain,
});
var channelCache = self._getCache(channel, domain);
return channelCache.messages;
});
cache = self._getCache(pDomain || []);
return cache.messages;
});
},
/**
* Posts the message on the Support server.
*
@@ -27,7 +27,8 @@ MessagingMenu.include({
this._super.apply(this, arguments);
this.supportChannel = {
id: SUPPORT_CHANNEL_ID,
name: _t("Support"),
name: _t("Odoo Live Support"),
title: _t("Odoo Live Support"),
imageSRC: '/mail/static/src/img/odoo_o.png',
};
},