[FIX] mail: restore mention links after note edition

- Open any record with a chatter (i.e. a SO)
- Log a note with a mention to any res.partner
- Edit note and save
The mention is not a link anymore, but just plain text.

During edition the list of mentioned partners is not retrieved correctly,
preventing function that generates links from mentions to work properly.

On client-side, a variable named MentionedPartners is used to generate
mention links when posting a message.
It should contain the id and name (to match the mention text) of each
mentioned partners.
During edition, MentionedPartners is empty, leading to this issue.
As the list of mentioned partners is stored in message model in partner_ids
field, "id" and "name" of partner_ids will be retrieved and added to messages
data when requested by client side.
This will allowed to populate MentionedPartners with all required data.

Note that retrieving "name" from partner_ids will add an extra query,
as seen in the modified test.

opw-2739665

closes odoo/odoo#84152

X-original-commit: 510764730057b20a1706ae20d50549e280f7f9a7
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Anh Thao Pham (pta)
2022-02-09 16:22:32 +00:00
parent eafcb1d823
commit e3dbb1b064
5 changed files with 19 additions and 4 deletions
+1 -1
View File
@@ -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
]
@@ -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(),
@@ -75,6 +75,7 @@ registerModel({
this.update({
composerForEditing: insertAndReplace({
isLastStateChangeProgrammatic: true,
mentionedPartners: replace(this.message.recipients),
textInputContent,
textInputCursorEnd: textInputContent.length,
textInputCursorStart: textInputContent.length,
@@ -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,
});
+1 -1
View File
@@ -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='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,