From 5835af85db4dcc40e93f6a65fd83ad556fa9d316 Mon Sep 17 00:00:00 2001 From: x620 Date: Wed, 8 Jun 2016 18:31:56 +0500 Subject: [PATCH] [IMP] Implements notifications for notice about change message moved status --- mail_move_message/controllers/main.py | 13 ++++++++ mail_move_message/mail_move_message_models.py | 2 +- .../static/src/js/mail_move_message.js | 32 +++++++++++-------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/mail_move_message/controllers/main.py b/mail_move_message/controllers/main.py index bef9074..24307ea 100644 --- a/mail_move_message/controllers/main.py +++ b/mail_move_message/controllers/main.py @@ -2,6 +2,19 @@ from openerp.addons.web.controllers.main import DataSet from openerp.tools.translate import _ from openerp import http from openerp.http import request +import openerp + + +class MailChatController(openerp.addons.bus.controllers.main.BusController): + # ----------------------------- + # Extends BUS Controller Poll + # ----------------------------- + def _poll(self, dbname, channels, last, options): + if request.session.uid: + registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.context + channels.append((request.db, 'mail_move_message')) + return super(MailChatController, self)._poll(dbname, channels, last, options) + class DataSetCustom(DataSet): diff --git a/mail_move_message/mail_move_message_models.py b/mail_move_message/mail_move_message_models.py index 5f58016..1762dec 100644 --- a/mail_move_message/mail_move_message_models.py +++ b/mail_move_message/mail_move_message_models.py @@ -309,7 +309,7 @@ class mail_message(models.Model): # Send notification notification = {'message_ids': [self.id], 'values': vals} - self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), notification) + self.env['bus.bus'].sendone((self._cr.dbname, 'mail_move_message'), notification) def name_get(self, cr, uid, ids, context=None): if not (context or {}).get('extended_name'): 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 039417b..37fb655 100644 --- a/mail_move_message/static/src/js/mail_move_message.js +++ b/mail_move_message/static/src/js/mail_move_message.js @@ -46,28 +46,34 @@ odoo.define('mail_move_message.relocate', function (require) { self.message_id = message_id; self.do_action(action, { - 'on_close': function(){ - var message = base_obj.chat_manager.get_message(self.message_id); - chat_manager.bus.trigger('update_message', message); - self.fetch_and_render_thread(); - bus.on('notification', null, self.on_notification); - } + 'on_close': function(){} }); - }, - on_notification: function(notification){ - var model = notification[0][1]; - if (model === 'ir.needaction') { - // new message in the inbox - chat_manager.mail_tools.on_needaction_notification(notification[1]); - } } }); base_obj.MailTools.include({ make_message: function(data){ var msg = this._super(data); + // Mark msg as moved after reload msg.is_moved = data.is_moved || false; return msg; + }, + on_notification: function(notifications){ + this._super(notifications); + _.each(notifications, function (notification) { + var model = notification[0][1]; + if (model === 'mail_move_message') { + var message_id = notification[1].message_ids[0]; + 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, []); + // Call ChatAction.on_update_message(message) + chat_manager.bus.trigger('update_message', message); + } + }); } });