[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.
This commit is contained in:
Jérome Maes
2015-10-06 09:44:51 +02:00
parent 2df240ded0
commit 2a676ee11c
3 changed files with 20 additions and 6 deletions
+2 -1
View File
@@ -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)
# --------------------------
+10
View File
@@ -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 """
+8 -5
View File
@@ -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') {