summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2015-11-04 14:20:55 +0100
committerGéry Debongnie <ged@odoo.com>2015-11-09 16:36:29 +0100
commit2bb55ecb041ebdc1074cbf6e138ad24df1fe0581 (patch)
tree86d19ada6a3ec91d194e1215f3d4f11b7bc3ec4c /addons/mail/static/src/js
parentfb013ce292bc0fdb4a2031de63ff56308471dfe4 (diff)
[FIX] mail: issue when leaving channel and refreshing
When we refresh, the bus will send the last notifications since the last 50s, so, the browser will receive notifications from a channel that we already left. This commits tries to fix the issue by sending explicitely the information that a channel was unsubscribed. Also, and this is touchy, it ignores messages received in a channel that it is not subscribed to (before, it joined the channel) Also, it will synchronize channels opened and closed in various tabs/browsers.
Diffstat (limited to 'addons/mail/static/src/js')
-rw-r--r--addons/mail/static/src/js/chat_manager.js19
-rw-r--r--addons/mail/static/src/js/client_action.js1
-rw-r--r--addons/mail/static/src/js/window_manager.js8
3 files changed, 20 insertions, 8 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index 9115ea995c8..325357a650e 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -487,18 +487,21 @@ function init () {
// new message in a channel
var message = notification[1];
var channel_id = message.channel_ids[0];
- // fetch the channel info if not done already
var channel = _.findWhere(channels, {id: channel_id});
- var channel_ready;
- if (!channel) {
- channel_ready = chat_manager.join_channel(channel_id, { autoswitch: false });
- }
- $.when(channel_ready).then(function () {
+ if (channel) {
add_message(message, { channel_id: channel_id, show_notification: true });
- });
+ }
}
if (model === 'res.partner') {
var chat_session = notification[1];
+ if (chat_session.info === "unsubscribe") {
+ var channel = _.findWhere(channels, {id: chat_session.id});
+ if (channel) {
+ channels = _.without(channels, channel);
+ }
+ chat_manager.bus.trigger("unsubscribe_from_channel", chat_session.id);
+ return;
+ }
if ((chat_session.channel_type === "channel") && (chat_session.public === "private") && (chat_session.state === "open")) {
add_channel(chat_session, {autoswitch: false});
if (!chat_session.is_minimized) {
@@ -507,7 +510,7 @@ function init () {
}
// partner specific change (open a detached window for example)
if ((chat_session.state === "open") || (chat_session.state === "folded")) {
- add_channel(chat_session, {autoswitch: false, silent: true, hidden: true});
+ add_channel(chat_session, {autoswitch: false});
if (chat_session.is_minimized) {
chat_manager.bus.trigger("open_chat", chat_session);
}
diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js
index 9a0f6f914d1..251f6e3b772 100644
--- a/addons/mail/static/src/js/client_action.js
+++ b/addons/mail/static/src/js/client_action.js
@@ -204,6 +204,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
query.is_displayed = query.is_displayed || channel.id === self.channel.id;
});
chat_manager.bus.on('update_needaction', self, self.on_update_needaction);
+ chat_manager.bus.on('unsubscribe_from_channel', self, self.render_sidebar);
});
},
diff --git a/addons/mail/static/src/js/window_manager.js b/addons/mail/static/src/js/window_manager.js
index 5c9a24b6dc5..aacf2a2919f 100644
--- a/addons/mail/static/src/js/window_manager.js
+++ b/addons/mail/static/src/js/window_manager.js
@@ -106,6 +106,14 @@ core.bus.on('web_client_ready', null, function () {
});
});
+ chat_manager.bus.on('unsubscribe_from_channel', null, function (channel_id) {
+ _.each(chat_sessions, function (session) {
+ if (channel_id === session.id) {
+ close_chat(session);
+ }
+ });
+ });
+
chat_manager.is_ready.then(function() {
_.each(chat_manager.get_channels(), function (channel) {
if (channel.is_detached) {