From fb013ce292bc0fdb4a2031de63ff56308471dfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 9 Nov 2015 15:38:55 +0100 Subject: [PATCH] [FIX] mail: prevent race condition in client action The issue was that the chat_manager was an async js module, so it could be loaded quite late. Then the client action was loaded only after the chat_manager was ready, and possibly before the action_manager read the value in the action registry. This commits prevent this problem from happening by turning the chat manager into a sync module, so the chatter and the client action needs to wait for him to be ready before doing their magic. --- addons/mail/static/src/js/chat_manager.js | 5 +++-- addons/mail/static/src/js/chatter.js | 5 ++++- addons/mail/static/src/js/client_action.js | 4 ++++ addons/mail/static/src/js/window_manager.js | 10 ++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 7fd42ef417c..9115ea995c8 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -524,10 +524,11 @@ function init () { action_id: action_id, }; bus.start_polling(); - return chat_manager; }); } -return init(); +chat_manager.is_ready = init(); + +return chat_manager; }); diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 0d261ea9053..5b98786ccdc 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -12,7 +12,6 @@ var data = require('web.data'); var Dialog = require('web.Dialog'); var form_common = require('web.form_common'); var session = require('web.session'); -var web_client = require('web.web_client'); var _t = core._t; var qweb = core.qweb; @@ -696,6 +695,10 @@ var Chatter = form_common.AbstractField.extend({ this.context = this.options.context || {}; }, + willStart: function () { + return chat_manager.is_ready; + }, + start: function () { var self = this; diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js index 78e5cca529f..9a0f6f914d1 100644 --- a/addons/mail/static/src/js/client_action.js +++ b/addons/mail/static/src/js/client_action.js @@ -127,6 +127,10 @@ var ChatAction = Widget.extend(ControlPanelMixin, { this.channels_scrolltop = {}; }, + willStart: function () { + return chat_manager.is_ready; + }, + start: function() { var self = this; diff --git a/addons/mail/static/src/js/window_manager.js b/addons/mail/static/src/js/window_manager.js index 4ba8cc23a68..5c9a24b6dc5 100644 --- a/addons/mail/static/src/js/window_manager.js +++ b/addons/mail/static/src/js/window_manager.js @@ -106,10 +106,12 @@ core.bus.on('web_client_ready', null, function () { }); }); - _.each(chat_manager.get_channels(), function (channel) { - if (channel.is_detached) { - open_chat(channel); - } + chat_manager.is_ready.then(function() { + _.each(chat_manager.get_channels(), function (channel) { + if (channel.is_detached) { + open_chat(channel); + } + }); }); });