From 79a8eeb17d16a12ea7ce8fa946dd610c32035bd0 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 4 Feb 2016 11:49:55 +0100 Subject: [PATCH] [FIX] mail: unread counter on new message in non pinned DM When a new message arrived in a non pinned DM, the unread counter was incremented twice ; once because the channel info (along with its unread counter) was fetched from the server as the channel wasn't in the JS cache yet, and once when adding the message in the JS. With this rev., we only increment the unread counter when a new message arrives if its channel is already in the JS cache. --- addons/mail/static/src/js/chat_manager.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 7c212041149..07f96727c13 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -529,13 +529,16 @@ function on_needaction_notification (message) { function on_channel_notification (message) { var def; + var channel_already_in_cache = true; if (message.channel_ids.length === 1) { + channel_already_in_cache = !!chat_manager.get_channel(message.channel_ids[0]); def = chat_manager.join_channel(message.channel_ids[0], {autoswitch: false}); } else { def = $.when(); } def.then(function () { - add_message(message, { show_notification: true, increment_unread: true }); + // don't increment unread if channel wasn't in cache yet as its unread counter has just been fetched + add_message(message, { show_notification: true, increment_unread: channel_already_in_cache }); invalidate_caches(message.channel_ids); }); }