From f10ead0ac85d0cd739954ab810ebdbd1aef6a278 Mon Sep 17 00:00:00 2001 From: Ambroise Decouttere Date: Wed, 30 Oct 2024 08:12:59 +0100 Subject: [PATCH] fix: Wait for cleanRealm before fetching --- .../General/SettingsThreadModeView.swift | 6 ++++- Mail/Views/Settings/SettingsView.swift | 3 --- .../MailboxManager/MailboxManager+DB.swift | 22 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Mail/Views/Settings/General/SettingsThreadModeView.swift b/Mail/Views/Settings/General/SettingsThreadModeView.swift index db8438ddc..5e4ff6b72 100644 --- a/Mail/Views/Settings/General/SettingsThreadModeView.swift +++ b/Mail/Views/Settings/General/SettingsThreadModeView.swift @@ -31,6 +31,7 @@ struct ThreadModeSettingUpdate: Identifiable { struct SettingsThreadModeView: View { @LazyInjectService private var matomo: MatomoUtils + @LazyInjectService private var accountManager: AccountManager @State private var selectedValue: ThreadMode @ModalState(wrappedValue: nil, context: ContextKeys.settings) private var threadModeSettingUpdate: ThreadModeSettingUpdate? @@ -73,7 +74,10 @@ struct SettingsThreadModeView: View { secondaryButtonTitle: MailResourcesStrings.Localizable.buttonCancel ) { selectedValue = threadModeUpdate.newSetting - UserDefaults.shared.threadMode = selectedValue + Task { + accountManager.updateConversationSettings() + UserDefaults.shared.threadMode = selectedValue + } } } } diff --git a/Mail/Views/Settings/SettingsView.swift b/Mail/Views/Settings/SettingsView.swift index 777db2e9e..53248c9d7 100644 --- a/Mail/Views/Settings/SettingsView.swift +++ b/Mail/Views/Settings/SettingsView.swift @@ -219,9 +219,6 @@ struct SettingsView: View { } } } - .onChange(of: threadMode) { _ in - accountManager.updateConversationSettings() - } .background(MailResourcesAsset.backgroundColor.swiftUIColor) .navigationBarTitle(MailResourcesStrings.Localizable.settingsTitle, displayMode: .inline) .backButtonDisplayMode(.minimal) diff --git a/MailCore/Cache/MailboxManager/MailboxManager+DB.swift b/MailCore/Cache/MailboxManager/MailboxManager+DB.swift index a6656850f..97e4c1afd 100644 --- a/MailCore/Cache/MailboxManager/MailboxManager+DB.swift +++ b/MailCore/Cache/MailboxManager/MailboxManager+DB.swift @@ -20,20 +20,18 @@ import Foundation public extension MailboxManager { func cleanRealm() { - Task { - try? writeTransaction { writableRealm in - let threads = writableRealm.objects(Thread.self) - writableRealm.delete(threads) + try? writeTransaction { writableRealm in + let threads = writableRealm.objects(Thread.self) + writableRealm.delete(threads) - let messages = writableRealm.objects(Message.self) - writableRealm.delete(messages) + let messages = writableRealm.objects(Message.self) + writableRealm.delete(messages) - let folders = writableRealm.objects(Folder.self) - for folder in folders { - folder.cursor = nil - folder.resetHistoryInfo() - folder.computeUnreadCount() - } + let folders = writableRealm.objects(Folder.self) + for folder in folders { + folder.cursor = nil + folder.resetHistoryInfo() + folder.computeUnreadCount() } } }