[FIX] mail: correctly compute unread messages

Two problems occured:
 - when the user hadn't seen any messages of a channel, the seen_message_id
   was null and doing seen_message_id < msg.id to retrieve all messages
   received after the last one seen didn't return any message (null < x is
   always false)

 - messages sent by visitor on the livechat doesn't have any author_id, so,
   again, doing msg.author_id != partner_id is always false, and as a
   consequence, server-side, the messages sent by visitors were always
   considered as read
This commit is contained in:
Aaron Bohy
2016-02-08 08:29:52 +01:00
parent 2b43624666
commit bc2d86e00f
+4 -2
View File
@@ -176,8 +176,10 @@ class MailThread(models.AbstractModel):
RIGHT JOIN mail_message_mail_channel_rel rel
ON rel.mail_message_id = msg.id
RIGHT JOIN mail_channel_partner cp
ON (cp.channel_id = rel.mail_channel_id AND cp.partner_id = %s AND (cp.seen_message_id < msg.id))
WHERE msg.model = %s AND msg.res_id in %s AND msg.author_id != %s AND
ON (cp.channel_id = rel.mail_channel_id AND cp.partner_id = %s AND
(cp.seen_message_id IS NULL OR cp.seen_message_id < msg.id))
WHERE msg.model = %s AND msg.res_id in %s AND
(msg.author_id IS NULL OR msg.author_id != %s) AND
(msg.message_type != 'notification' OR msg.model != 'mail.channel')""",
(partner_id, self._name, tuple(self.ids), partner_id,))
for result in self._cr.fetchall():