From 2a676ee11c7d68b85fd4d05eeb8344eab0096459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Fri, 2 Oct 2015 14:54:05 +0200 Subject: [PATCH] [FIX] mail : broadcast needaction for concerned partners in particular bus channel Use the (dbname, 'ir.needaction', partner_id) channel to broadcast needaction to partner. Some message can be needaction, without belonging to a mail channel of the partner. Keep the (dbname, 'res.partner', partner_id) channel for conversation header. --- addons/mail/controllers/bus.py | 3 ++- addons/mail/models/res_partner.py | 10 ++++++++++ addons/mail/static/src/js/chat_manager.js | 13 ++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/addons/mail/controllers/bus.py b/addons/mail/controllers/bus.py index 3de670a8bbe..03075fe04ad 100644 --- a/addons/mail/controllers/bus.py +++ b/addons/mail/controllers/bus.py @@ -25,8 +25,9 @@ class MailChatController(openerp.addons.bus.controllers.main.BusController): if partner_id: for mail_channel in request.env['mail.channel'].search([('channel_partner_ids', 'in', [partner_id])]): channels.append((request.db, 'mail.channel', mail_channel.id)) - # personal channel + # personal and needaction channel channels.append((request.db, 'res.partner', partner_id)) + channels.append((request.db, 'ir.needaction', partner_id)) return super(MailChatController, self)._poll(dbname, channels, last, options) # -------------------------- diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index fa24fb9055f..cdf02ba1b82 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -124,6 +124,7 @@ class Partner(models.Model): ('channel_ids', 'in', email_channels.ids), ('email', '!=', message_sudo.author_id and message_sudo.author_id.email or message.email_from), ('notify_email', '!=', 'none')])._notify_by_email(message, force_send=force_send, user_signature=user_signature) + self._notify_by_chat(message) return True @api.multi @@ -188,6 +189,15 @@ class Partner(models.Model): return True + @api.multi + def _notify_by_chat(self, message): + """ Broadcast the message to all the partner since """ + message_values = message.message_format()[0] + notifications = [] + for partner in self: + notifications.append([(self._cr.dbname, 'ir.needaction', partner.id), dict(message_values)]) + self.env['bus.bus'].sendmany(notifications) + @api.model def get_needaction_count(self): """ compute the number of needaction of the current user """ diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index df57cc8bbfa..2f2542e7e3f 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -438,6 +438,13 @@ function init () { bus.on('notification', null, function (notification) { var model = notification[0][1]; + if (model === 'ir.needaction') { + // new message in the inbox + var message = notification[1]; + message = add_message(message, { channel_id: 'channel_inbox', show_notification: true} ); + needaction_counter = needaction_counter + 1; + chat_manager.bus.trigger('update_needaction', needaction_counter); + } if (model === 'mail.channel') { // new message in a channel var message = notification[1]; @@ -449,11 +456,7 @@ function init () { channel_ready = chat_manager.join_channel(channel_id, { autoswitch: false }); } $.when(channel_ready).then(function () { - message = add_message(message, { channel_id: channel_id, show_notification: true }); - if (_.contains(message.channel_ids, 'channel_inbox')) { - needaction_counter = needaction_counter + 1; - chat_manager.bus.trigger('update_needaction', needaction_counter); - } + add_message(message, { channel_id: channel_id, show_notification: true }); }); } if (model === 'res.partner') {