From 8ee218aa5caa6ee10e10e47b80fb384e2e0a7a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 13 Feb 2019 14:21:27 +0000 Subject: [PATCH] [FIX] mail: notify channel_fetched/channel_seen only when changes Revision on https://github.com/odoo/odoo/commit/844fb2b51ea7cfa557b19466c0a53dde19433e7a With the commit above, when the JS notified on `channel_fetched` and `channel_seen`, it was always writing in DB and sending notifications on the longpoll. This is useless if the information on last fetched/seen message of the conversation remains unchanged, which is what this commit solves. Also prevent `channel_fetched` from seding notifications on the longpoll if this is called on a non-chat channel. --- addons/mail/models/mail_channel.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index dbac168ef77..37b4d222c26 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -730,7 +730,11 @@ class Channel(models.Model): self.ensure_one() if self.channel_message_ids.ids: last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message - self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]).write({ + channel_partner = self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]) + if channel_partner.seen_message_id.id == last_message_id: + # last message seen by user is already up-to-date + return + channel_partner.write({ 'seen_message_id': last_message_id, 'fetched_message_id': last_message_id, }) @@ -754,8 +758,14 @@ class Channel(models.Model): for channel in self: if not channel.channel_message_ids.ids: return + if channel.channel_type != 'chat': + return last_message_id = channel.channel_message_ids.ids[0] # zero is the index of the last message - self.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', self.env.user.partner_id.id)]).write({ + channel_partner = self.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', self.env.user.partner_id.id)]) + if channel_partner.fetched_message_id.id == last_message_id: + # last message fetched by user is already up-to-date + return + channel_partner.write({ 'fetched_message_id': last_message_id, }) data = {