[IMP] mail: simplify compute of allAttachments with sort

Part of task-2925723

Part-of: odoo/odoo#104478
This commit is contained in:
Sébastien Theys
2022-10-31 12:42:18 +01:00
parent 389d040faa
commit daa7cfaf4d
+5 -13
View File
@@ -1104,21 +1104,13 @@ registerModel({
}),
allAttachments: many('Attachment', {
compute() {
const allAttachments = [...new Set(this.originThreadAttachments.concat(this.attachments))]
.sort((a1, a2) => {
// "uploading" before "uploaded" attachments.
if (!a1.isUploading && a2.isUploading) {
return 1;
}
if (a1.isUploading && !a2.isUploading) {
return -1;
}
// "most-recent" before "oldest" attachments.
return Math.abs(a2.id) - Math.abs(a1.id);
});
return allAttachments;
return [...new Set(this.originThreadAttachments.concat(this.attachments))];
},
inverse: 'allThreads',
sort: [
['truthy-first', 'isUploading'],
['greater-first', 'id'],
],
}),
areAttachmentsLoaded: attr({
default: false,