From bc2d86e00f263d9583fb66ae0d451cf911474a7b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 5 Feb 2016 14:08:05 +0100 Subject: [PATCH] [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 --- addons/mail/models/mail_thread.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 91699c29d92..670f9eea599 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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():