From 74dd220c4f0bfe26f33d51ceabf62b88b5a9a139 Mon Sep 17 00:00:00 2001 From: x620 Date: Tue, 14 Jun 2016 11:38:01 +0500 Subject: [PATCH] [FIX] Implement removal message from channel when a notification is triggered --- mail_move_message/mail_move_message_models.py | 2 +- .../static/src/js/mail_move_message.js | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mail_move_message/mail_move_message_models.py b/mail_move_message/mail_move_message_models.py index ad4c54d..c05deff 100644 --- a/mail_move_message/mail_move_message_models.py +++ b/mail_move_message/mail_move_message_models.py @@ -196,12 +196,12 @@ class wizard(models.TransientModel): @api.one def delete(self): msg_id = self.message_id.id - self.message_id.unlink() # Send notification notification = {'message_ids': [msg_id]} self.env['bus.bus'].sendone((self._cr.dbname, 'mail_move_message.delete_message'), notification) + self.message_id.unlink() return {} @api.model diff --git a/mail_move_message/static/src/js/mail_move_message.js b/mail_move_message/static/src/js/mail_move_message.js index 458d6f9..04537bd 100644 --- a/mail_move_message/static/src/js/mail_move_message.js +++ b/mail_move_message/static/src/js/mail_move_message.js @@ -60,29 +60,31 @@ odoo.define('mail_move_message.relocate', function (require) { }, on_notification: function(notifications){ this._super(notifications); + var self = this; _.each(notifications, function (notification) { var model = notification[0][1]; var message_id = notification[1].message_ids[0]; + var message = base_obj.chat_manager.get_message(message_id); if (model === 'mail_move_message') { - var message = base_obj.chat_manager.get_message(message_id); - // Mark message as moved after move and for update cache message.is_moved = notification[1].values.is_moved; // Update cache and accordingly message in the thread - chat_manager.mail_tools.add_to_cache(message, []); + self.add_to_cache(message, []); // Call ChatAction.on_update_message(message) chat_manager.bus.trigger('update_message', message); } else if (model === 'mail_move_message.delete_message') { - chat_manager.get_messages( - // TODO: получить channel.id и this.domain - {channel_id: this.channel.id, domain: this.domain} - ).then(function (messages) { - var options = self.get_thread_rendering_options(messages); - thread.remove_message_and_render(message_id, messages, options) - .then(function () { - self.update_button_status(messages.length === 0); - }); + // Remove message from cache + _.each(message.channel_ids, function (channel_id) { + var channel = chat_manager.get_channel(channel_id); + if (channel) { + var channel_cache = self.get_channel_cache(channel, []); + var index = _.sortedIndex(channel_cache.messages, message, 'id'); + if (channel_cache.messages[index] === message) { + channel_cache.messages.splice(index, 1); + } + } }); + chat_manager.bus.trigger('update_message', message); } }); }