[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 forward port of commit 69714fbeee
done in saas-11.2.
This commit is contained in:
Xavier Dollé
2018-05-16 16:17:59 +02:00
committed by Thibault Delavallée
parent 6a601fe6dc
commit f555bfeca3
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -402,7 +402,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())
@@ -418,6 +417,7 @@ class Message(models.Model):
note_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_note')
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]]['id'] == note_id
message['is_discussion'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == com_id
message['is_notification'] = message['is_note'] and not message['model'] and not message['res_id']
+3 -3
View File
@@ -206,7 +206,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_assignation_inbox(self):
record = self.env['mail.test.track'].create({'name': 'Test'})
with self.assertQueryCount(margin=1, admin=42, emp=55): # test_mail only: 42 - 55
with self.assertQueryCount(margin=1, admin=44, emp=55): # test_mail only: 44 - 55
record.write({
'user_id': self.user_test.id,
})
@@ -262,7 +262,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_one_inbox_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(margin=1, admin=37, emp=48): # com runbot 35 - 46 // test_mail only: 37 - 48
with self.assertQueryCount(margin=1, admin=39, emp=48): # com runbot 37 - 46 // test_mail only: 39 - 48
record.message_post(
body='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,
@@ -472,7 +472,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id)
with self.assertQueryCount(admin=67, emp=87): # com runbot: 66 - 86 // test_mail only: 67 - 87
with self.assertQueryCount(admin=67, emp=85): # com runbot: 66 - 84 // test_mail only: 67 - 85
rec.write({'user_id': self.user_portal.id})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)