From 79a7b4386dc17c9d1dccc11c38caebb484250824 Mon Sep 17 00:00:00 2001 From: x620 Date: Tue, 14 Jun 2016 12:12:28 +0500 Subject: [PATCH] [REF] Replaced code from mail_move_message.js to remove_from_cache() method to base.js for reuse --- mail_base/static/src/js/base.js | 14 ++++++++++++++ .../static/src/js/mail_move_message.js | 12 +----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mail_base/static/src/js/base.js b/mail_base/static/src/js/base.js index 098318e..a9816f1 100644 --- a/mail_base/static/src/js/base.js +++ b/mail_base/static/src/js/base.js @@ -495,6 +495,20 @@ var MailTools = core.Class.extend({ }); }, + remove_from_cache: function(message, domain){ + var self = this; + _.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, domain); + var index = _.sortedIndex(channel_cache.messages, message, 'id'); + if (channel_cache.messages[index] === message) { + channel_cache.messages.splice(index, 1); + } + } + }); + }, + remove_message_from_channel: function (channel_id, message) { message.channel_ids = _.without(message.channel_ids, channel_id); var channel = _.findWhere(channels, { id: channel_id }); 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 04537bd..8f5661a 100644 --- a/mail_move_message/static/src/js/mail_move_message.js +++ b/mail_move_message/static/src/js/mail_move_message.js @@ -73,17 +73,7 @@ odoo.define('mail_move_message.relocate', function (require) { // Call ChatAction.on_update_message(message) chat_manager.bus.trigger('update_message', message); } else if (model === 'mail_move_message.delete_message') { - // 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); - } - } - }); + self.remove_from_cache(message, []); chat_manager.bus.trigger('update_message', message); } });