[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.
This commit is contained in:
@@ -150,7 +150,7 @@ class Channel(models.Model):
|
||||
@api.multi
|
||||
def action_unfollow(self):
|
||||
result = self.write({'channel_partner_ids': [(3, self.env.user.partner_id.id)]})
|
||||
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), self.channel_info()[0])
|
||||
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), self.channel_info('unsubscribe')[0])
|
||||
notification = _('<div class="o_mail_notification">left <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>') % (self.id, self.name,)
|
||||
self.message_post(body=notification, message_type="notification", subtype="mail.mt_comment")
|
||||
return result
|
||||
@@ -251,7 +251,7 @@ class Channel(models.Model):
|
||||
return notifications
|
||||
|
||||
@api.multi
|
||||
def channel_info(self):
|
||||
def channel_info(self, extra_info = False):
|
||||
""" Get the informations header for the current channels
|
||||
:returns a list of channels values
|
||||
:rtype : list(dict)
|
||||
@@ -272,6 +272,8 @@ class Channel(models.Model):
|
||||
'channel_type': channel.channel_type,
|
||||
'public': channel.public,
|
||||
}
|
||||
if extra_info:
|
||||
info['info'] = extra_info
|
||||
# add the partner for 'direct mesage' channel
|
||||
if channel.channel_type == 'chat':
|
||||
info['direct_partner'] = channel.sudo().channel_partner_ids.filtered(lambda p: p.id != self.env.user.partner_id.id).read(['id', 'name', 'im_status'])
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user