Skip to content

Commit

Permalink
fix: Wait for cleanRealm before fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrdctr authored and PhilippeWeidmann committed Nov 1, 2024
1 parent f428f44 commit 990c8fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 5 additions & 1 deletion Mail/Views/Settings/General/SettingsThreadModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions Mail/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 10 additions & 12 deletions MailCore/Cache/MailboxManager/MailboxManager+DB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down

0 comments on commit 990c8fd

Please sign in to comment.