[FIX] im_livechat,mail: detach chat on the receiver side

This commit concerns DM and livechat channels. Those channels are now
automatically detached on the receiver side. This allows users to directly
reply to DM's or livechats without coming back to the client action.

Note that they aren't detached if the user previously manually closed the
channel's chat window.
This commit is contained in:
Aaron Bohy
2015-11-20 15:48:03 +01:00
parent c2dfea5cc9
commit a8239cd2ae
2 changed files with 21 additions and 7 deletions
@@ -173,6 +173,8 @@ class ImLivechatChannel(models.Model):
'public': 'public',
'email_send': False,
})
# minimize channel on operator's side
mail_channel._minimize([operator_partner_id])
return mail_channel.sudo().with_context(im_livechat_operator_partner_id=operator_partner_id).channel_info()[0]
@api.model
+19 -7
View File
@@ -140,6 +140,16 @@ class Channel(models.Model):
for mail_channel in self:
mail_channel.write({'channel_partner_ids': [(4, pid) for pid in mail_channel.mapped('group_ids').mapped('users').mapped('partner_id').ids]})
@api.multi
def _minimize(self, partner_ids):
self.ensure_one()
domain = [('channel_id', '=', self.id), ('partner_id', 'in', tuple(partner_ids))]
channel_partners = self.env['mail.channel.partner'].search(domain)
channel_partners.write({
'is_minimized': True,
'fold_state': 'open',
})
@api.multi
def action_follow(self):
self.ensure_one()
@@ -317,8 +327,8 @@ class Channel(models.Model):
:rtype : dict
"""
if partners_to:
partners_to.append(self.env.user.partner_id.id)
# determine type according to the number of partner in the channel
partners = partners_to + [self.env.user.partner_id.id]
# determine type according to the number of partners in the channel
self.env.cr.execute("""
SELECT P.channel_id as channel_id
FROM mail_channel C, mail_channel_partner P
@@ -328,7 +338,7 @@ class Channel(models.Model):
AND channel_type LIKE 'chat'
GROUP BY P.channel_id
HAVING COUNT(P.partner_id) = %s
""", (tuple(partners_to), len(partners_to),))
""", (tuple(partners), len(partners),))
result = self.env.cr.dictfetchall()
if result:
# get the existing channel between the given partners
@@ -339,14 +349,16 @@ class Channel(models.Model):
else:
# create a new one
channel = self.create({
'channel_partner_ids': [(4, partner_id) for partner_id in partners_to],
'channel_partner_ids': [(4, partner_id) for partner_id in partners],
'public': 'private',
'channel_type': 'chat',
'email_send': False,
'name': ', '.join(self.env['res.partner'].sudo().browse(partners_to).mapped('name')),
'name': ', '.join(self.env['res.partner'].sudo().browse(partners).mapped('name')),
})
# broadcast the channel header to the other partner (not me)
channel._broadcast(partners_to)
# minimize the DM on other partners' side
channel._minimize(partners_to)
# broadcast the channel header
channel._broadcast(partners)
return channel.channel_info()[0]
return False