From daa7cfaf4d60286d506e1d0df69cace0c0b4408b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 28 Oct 2022 12:47:01 +0000 Subject: [PATCH] [IMP] mail: simplify compute of allAttachments with sort Part of task-2925723 Part-of: odoo/odoo#104478 --- addons/mail/static/src/models/thread.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index de785d810a1..5db2c936075 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -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,