Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wait for cleanRealm before fetching #1601

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
await accountManager.cleanAllRealms()
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
2 changes: 1 addition & 1 deletion MailCore/Cache/AccountManager/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public final class AccountManager: RefreshTokenDelegate, ObservableObject {
}
}

public func updateConversationSettings() {
public func cleanAllRealms() async {
for account in accounts {
for mailbox in mailboxInfosManager.getMailboxes(for: account.userId) {
if let mailboxManager = getMailboxManager(for: mailbox) {
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
Loading