diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 4a96c7e4991..daca9e6e019 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -974,6 +974,7 @@ class Message(models.Model): 'is_discussion': message_sudo.subtype_id.id == com_id, 'subtype_description': message_sudo.subtype_id.description, 'is_notification': vals['message_type'] == 'user_notification', + 'recipients': [{'id': p.id, 'name': p.name} for p in message_sudo.partner_ids], }) if vals['model'] and self.env[vals['model']]._original_module: vals['module_icon'] = modules.module.get_module_icon(self.env[vals['model']]._original_module) @@ -984,7 +985,6 @@ class Message(models.Model): 'id', 'body', 'date', 'author_id', 'email_from', # base message fields 'message_type', 'subtype_id', 'subject', # message specific 'model', 'res_id', 'record_name', # document related - 'partner_ids', # recipients 'starred_partner_ids', # list of partner ids for whom the message is starred ] diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js index 2769edeebd6..be9d010037a 100644 --- a/addons/mail/static/src/models/message/message.js +++ b/addons/mail/static/src/models/message/message.js @@ -106,8 +106,8 @@ registerModel({ data2.parentMessage = insertAndReplace(this.convertData(data.parentMessage)); } } - if ('partner_ids' in data && this.messaging.currentPartner) { - data2.isCurrentPartnerMentioned = data.partner_ids.includes(this.messaging.currentPartner.id); + if ('recipients' in data) { + data2.recipients = insertAndReplace(data.recipients); } if ('starred_partner_ids' in data && this.messaging.currentPartner) { data2.isStarred = data.starred_partner_ids.includes(this.messaging.currentPartner.id); @@ -421,6 +421,13 @@ registerModel({ const inlineBody = htmlToTextContentInline(this.body); return inlineBody.toLowerCase() === this.subtype_description.toLowerCase(); }, + /** + * @private + * @returns {boolean} + */ + _computeIsCurrentPartnerMentioned() { + return this.recipients.includes(this.messaging.currentPartner); + }, /** * The method does not attempt to cover all possible cases of empty * messages, but mostly those that happen with a standard flow. Indeed @@ -704,6 +711,7 @@ registerModel({ * Determine whether the current partner is mentioned. */ isCurrentPartnerMentioned: attr({ + compute: '_computeIsCurrentPartnerMentioned', default: false, }), /** @@ -762,6 +770,7 @@ registerModel({ compute: '_computePrettyBody', default: "", }), + recipients: many('Partner'), subject: attr(), subtype_description: attr(), subtype_id: attr(), diff --git a/addons/mail/static/src/models/message_view/message_view.js b/addons/mail/static/src/models/message_view/message_view.js index e0017954358..cc56bfd5c75 100644 --- a/addons/mail/static/src/models/message_view/message_view.js +++ b/addons/mail/static/src/models/message_view/message_view.js @@ -75,6 +75,7 @@ registerModel({ this.update({ composerForEditing: insertAndReplace({ isLastStateChangeProgrammatic: true, + mentionedPartners: replace(this.message.recipients), textInputContent, textInputCursorEnd: textInputContent.length, textInputCursorStart: textInputContent.length, diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index 32cd25dcbc0..a09c02c17e1 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -1431,12 +1431,17 @@ MockServer.include({ const trackingValueIds = this._getRecords('mail.tracking.value', [ ['id', 'in', message.tracking_value_ids], ]); + const partners = this._getRecords( + 'res.partner', + [['id', 'in', message.partner_ids]], + ); const response = Object.assign({}, message, { attachment_ids: formattedAttachments, author_id: formattedAuthor, history_partner_ids: historyPartnerIds, needaction_partner_ids: needactionPartnerIds, notifications, + recipients: partners.map(p => ({ id: p.id, name: p.name })), record_name: thread && (thread.name !== undefined ? thread.name : thread.display_name), tracking_value_ids: trackingValueIds, }); diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index b9ec8595e9f..29a014a18a2 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -428,7 +428,7 @@ class TestMailAPIPerformance(BaseMailPerformance): def test_message_post_one_inbox_notification(self): record = self.env['mail.test.simple'].create({'name': 'Test'}) - with self.assertQueryCount(__system__=12, employee=16): + with self.assertQueryCount(__system__=13, employee=17): record.message_post( body='

Test Post Performances with an inbox ping

', partner_ids=self.user_test.partner_id.ids,