From c9380e3f8fcadf9b7a012122bd925831ab8ba98f Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 22 Feb 2024 15:30:31 +0100 Subject: [PATCH] fix: Prevent race condition when updating messages and drafts --- .../Cache/MailboxManager/MailboxManager+Thread.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MailCore/Cache/MailboxManager/MailboxManager+Thread.swift b/MailCore/Cache/MailboxManager/MailboxManager+Thread.swift index 2181f25af..47fba72ec 100644 --- a/MailCore/Cache/MailboxManager/MailboxManager+Thread.swift +++ b/MailCore/Cache/MailboxManager/MailboxManager+Thread.swift @@ -76,7 +76,14 @@ public extension MailboxManager { let foldersToUpdate = Set(threadsToUpdate.compactMap(\.folder)) try? realm.safeWrite { - realm.delete(draftsToDelete) + for draft in draftsToDelete { + if draft.action == nil { + realm.delete(draft) + } else { + draft.remoteUUID = "" + } + } + realm.delete(messagesToDelete) for thread in threadsToUpdate { if thread.messageInFolderCount == 0 {