[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.
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user