05/17 Fix bugs 4
This commit is contained in:
@@ -1035,7 +1035,14 @@ struct SettingsView: View {
|
||||
|
||||
Section {
|
||||
Button(role: .destructive) {
|
||||
Task { await auth.logout() }
|
||||
Task {
|
||||
// Clear server-pulled issues before logging out so stale
|
||||
// records from a previous server/domain don't persist into
|
||||
// the next session. Device-created pending issues are preserved.
|
||||
clearServerPulledData()
|
||||
sync.resetNotificationPoller()
|
||||
await auth.logout()
|
||||
}
|
||||
} label: {
|
||||
Label("Log Out", systemImage: "rectangle.portrait.and.arrow.right")
|
||||
}
|
||||
@@ -1073,4 +1080,17 @@ struct SettingsView: View {
|
||||
Task { await sync.pullReferenceData() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete all server-pulled LocalIssue records (syncStatus == "synced" and
|
||||
/// inspectionLocalId == ""). These are issues fetched from the server and
|
||||
/// reconciled by pullAssignedIssues — they must be cleared on logout so
|
||||
/// stale records from a previous server domain or user session don't persist.
|
||||
/// Device-created issues (inspectionLocalId != "") are never touched.
|
||||
private func clearServerPulledData() {
|
||||
let allIssues = (try? context.fetch(FetchDescriptor<LocalIssue>())) ?? []
|
||||
allIssues
|
||||
.filter { $0.syncStatus == "synced" && $0.inspectionLocalId == "" }
|
||||
.forEach { context.delete($0) }
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user