From 4e094189f9bf6d49712e2acade331546680db72a Mon Sep 17 00:00:00 2001 From: Soncrits Date: Tue, 9 Apr 2024 08:29:19 +0700 Subject: [PATCH] [FIX] mail: call rpc before remove attachment or message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Current Status - when remove attachment or message, The system will perform deletion on the interface before performing deletion in the DB. However, in some situations, exceptions will occur during the deletion process. So it will happen that the attachment or message has been deleted on the interface but still exists under the database. From a function that helps optimize user experience, it will cause a worse situation with user experience * Solution - Make rpc calls before deleting messages or attachments on the interface closes odoo/odoo#161023 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/core/common/attachment_service.js | 2 +- .../mail/static/src/core/common/message_service.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/mail/static/src/core/common/attachment_service.js b/addons/mail/static/src/core/common/attachment_service.js index 412768ddc61..463f7e0ed89 100644 --- a/addons/mail/static/src/core/common/attachment_service.js +++ b/addons/mail/static/src/core/common/attachment_service.js @@ -38,7 +38,6 @@ export class AttachmentService { * @param {Attachment} attachment */ async delete(attachment) { - this.remove(attachment); if (attachment.id > 0) { await this.rpc( "/mail/attachment/delete", @@ -48,6 +47,7 @@ export class AttachmentService { ) ); } + this.remove(attachment); } } diff --git a/addons/mail/static/src/core/common/message_service.js b/addons/mail/static/src/core/common/message_service.js index 935fcb1ca16..8949bcd647a 100644 --- a/addons/mail/static/src/core/common/message_service.js +++ b/addons/mail/static/src/core/common/message_service.js @@ -55,18 +55,18 @@ export class MessageService { } async delete(message) { - if (message.isStarred) { - this.store.discuss.starred.counter--; - this.store.discuss.starred.messages.delete(message); - } - message.body = ""; - message.attachments = []; await this.rpc("/mail/message/update_content", { attachment_ids: [], attachment_tokens: [], body: "", message_id: message.id, }); + if (message.isStarred) { + this.store.discuss.starred.counter--; + this.store.discuss.starred.messages.delete(message); + } + message.body = ""; + message.attachments = []; } /**