From 77acb57e55f0ea84cf021ccbb24c178b7f772673 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 4 Dec 2015 11:00:18 +0100 Subject: [PATCH] [FIX] mail: correctly increment channels' unread counter When several channels followed the same document, and a message was sent in this document, the unread counter of each channel was incremented by the number of following channels (because as many notifications were sent on the bus, and for each notification, we incremented the unread_counter of the channels in which the corresponding message is posted). This rev. makes sure to only increment the unread counter once, if the message is not yet in the JS cache, i.e. if this is the first notification we receive for this message. --- addons/mail/static/src/js/chat_manager.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index b60f9a056c9..f780163689d 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -48,6 +48,9 @@ function add_message (data, options) { if (options.domain && options.domain !== []) { add_to_cache(msg, options.domain); } + if (options.increment_unread) { + update_channel_unread_counter(channel, channel.unread_counter+1); + } } if (channel && channel.hidden) { channel.hidden = false; @@ -380,13 +383,7 @@ function on_channel_notification (message) { def = $.when(); } def.then(function () { - _.each(message.channel_ids, function (channel_id) { - var channel = chat_manager.get_channel(channel_id); - if (channel) { - update_channel_unread_counter(channel, channel.unread_counter+1); - } - }); - add_message(message, { show_notification: true }); + add_message(message, { show_notification: true, increment_unread: true }); invalidate_caches(message.channel_ids); }); }