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