[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.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user