[FIX] mail: correctly filter needaction on unread notifications in message_format
Previously to this commit needaction used by JS was not taking into account
read notifications. It means notably Inbox counter could be higher than
expected as taking into account read messages while Inbox displays only
unread messages. This commit fixes that by checking notification state when
giving needaction_partner_ids to message_format result.
This fix has a small impact on performances as message_format is used in
notification process for chat or push. A better implementation of message
format and its postprocess could probably lessen this fix impact. As we
target stable version we avoid rewriting other part of the code. Optimization
will be done in development version.
Related to task ID 1841243. This is a manual backport of commit 69714fbeee
done in saas-11.2.
This commit is contained in:
committed by
Thibault Delavallée
parent
491243d1ca
commit
19fb650863
@@ -411,7 +411,6 @@ class Message(models.Model):
|
||||
'message_type', 'subtype_id', 'subject', # message specific
|
||||
'model', 'res_id', 'record_name', # document related
|
||||
'channel_ids', 'partner_ids', # recipients
|
||||
'needaction_partner_ids', # list of partner ids for whom the message is a needaction
|
||||
'starred_partner_ids', # list of partner ids for whom the message is starred
|
||||
])
|
||||
message_tree = dict((m.id, m) for m in self.sudo())
|
||||
@@ -423,6 +422,7 @@ class Message(models.Model):
|
||||
subtypes = self.env['mail.message.subtype'].sudo().browse(subtype_ids).read(['internal', 'description'])
|
||||
subtypes_dict = dict((subtype['id'], subtype) for subtype in subtypes)
|
||||
for message in message_values:
|
||||
message['needaction_partner_ids'] = self.env['mail.notification'].sudo().search([('mail_message_id', '=', message['id']), ('is_read', '=', False)]).mapped('res_partner_id').ids
|
||||
message['is_note'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['internal']
|
||||
message['subtype_description'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['description']
|
||||
if message['model'] and self.env[message['model']]._original_module:
|
||||
|
||||
@@ -141,7 +141,7 @@ class TestPerformance(TransactionCase):
|
||||
|
||||
records.write({'value': self.int(20)})
|
||||
|
||||
@queryCount(admin=33, demo=47)
|
||||
@queryCount(admin=35, demo=47)
|
||||
def test_write_mail_with_tracking(self):
|
||||
""" Write records inheriting from 'mail.thread' (with field tracking). """
|
||||
record = self.env['test_performance.mail'].search([], limit=1)
|
||||
@@ -180,7 +180,7 @@ class TestPerformance(TransactionCase):
|
||||
model = self.env['test_performance.mail']
|
||||
model.with_context(tracking_disable=True).create({'name': self.str('X')})
|
||||
|
||||
@queryCount(admin=63, demo=85)
|
||||
@queryCount(admin=67, demo=85)
|
||||
def test_create_mail_with_tracking(self):
|
||||
""" Create records inheriting from 'mail.thread' (with field tracking). """
|
||||
model = self.env['test_performance.mail']
|
||||
|
||||
Reference in New Issue
Block a user