From 196e1322f208958634bf44d2cbff99295670e3cd Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 13 Nov 2015 14:28:18 +0100 Subject: [PATCH] [FIX] mail: needactions: mark as (un)read Marking a message as read in the inbox doesn't remove needactions on all channels anymore. When joining a channel (other than the inbox) in which there are needactions, those needactions are automatically marked as read and removed from the inbox. When the user clicked on Undo in the snackbar, the messages weren't correctly re-inserted in the inbox (in the JS cache). --- addons/mail/static/src/js/chat_manager.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 01cc6918264..e5913f4232b 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -378,14 +378,14 @@ function on_mark_as_read_notification (data) { chat_manager.bus.trigger('update_message', message); } }); - if (data.channel_ids.length) { + if (data.channel_ids) { _.each(data.channel_ids, function (channel_id) { var channel = chat_manager.get_channel(channel_id); if (channel) { channel.needaction_counter -= data.message_ids.length; } }); - } else { + } else { // if no channel_ids specified, this is a 'mark all read' in the inbox _.each(channels, function (channel) { channel.needaction_counter = 0; }); @@ -395,6 +395,12 @@ function on_mark_as_read_notification (data) { } function on_mark_as_unread_notification (data) { + _.each(data.message_ids, function (message_id) { + var message = _.findWhere(messages, { id: message_id }); + if (message) { + add_channel_to_message(message, 'channel_inbox'); + } + }); _.each(data.channel_ids, function (channel_id) { var channel = chat_manager.get_channel(channel_id); if (channel) { @@ -468,7 +474,7 @@ var chat_manager = { }, mark_all_as_read: function (channel) { if ((!channel && needaction_counter) || (channel && channel.needaction_counter)) { - return MessageModel.call('mark_all_as_read', channel ? [[channel.id]] : [[]]); + return MessageModel.call('mark_all_as_read', channel ? [[channel.id]] : []); } return $.when(); },