summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2019-02-13 14:21:27 +0000
committerAlexandre Kühn <aku@odoo.com>2019-02-14 12:55:24 +0000
commit8ee218aa5caa6ee10e10e47b80fb384e2e0a7a8b (patch)
treeb633cb8e23428bf12c2d79af9374eb4a678aaf38 /addons
parent62294921b81325131f6c1d4c6cf757c7da457ebc (diff)
[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.
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/models/mail_channel.py14
1 files 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 = {