Aug 19 - Fixed photo-loss issue

This commit is contained in:
Nguyen Ngo
2026-08-19 10:31:20 -04:00
parent 7cbc514c39
commit e31cd7e1ff
13 changed files with 856 additions and 149 deletions
+20 -23
View File
@@ -129,13 +129,17 @@ struct SettingsView: View {
Section {
Button(role: .destructive) {
Task {
// Do NOT clear server-pulled data on a plain logout
// the user is logging out of the same server, so cached
// facilities, issues, and templates are still valid on
// their next login. Clearing here leaves the issues list
// empty until a full sync succeeds, which breaks offline use.
// Server-pulled data is only cleared when switching servers
// (see the Switch & Log Out alert below).
// Do NOT purge on a plain logout the same inspector
// signing back into the same server must still find
// their facilities, templates and issues there, or the
// app is unusable offline until a full sync succeeds.
//
// What was missing is not a purge here: it is the check
// that the next sign-in is the SAME person.
// AuthManager.reconcileSessionScope() now does that at
// login and purges only on an identity change, so a
// different inspector no longer inherits this one's
// issues (rule 88).
sync.resetNotificationPoller()
await auth.logout()
}
@@ -207,7 +211,14 @@ struct SettingsView: View {
settingsServer = chosen
pendingServer = nil
Task {
clearServerPulledData()
// Purge EVERYTHING, not just issues. The old
// clearServerPulledData() deleted LocalIssue alone,
// leaving LocalInspection rows carrying facility and
// template ids that name different rows on the server
// being switched to ready to be submitted against it.
// Nothing local survives a server change (rule 88).
sync.purgeSessionScopedData(keepingUserId: nil, sameServer: false)
SessionScope.clear()
sync.resetNotificationPoller()
await auth.logout()
}
@@ -218,7 +229,7 @@ struct SettingsView: View {
}
} message: {
if let chosen = pendingServer {
Text("Switching to \(chosen.displayName) will log you out. All cached server data will be cleared. You will need to log in again.")
Text("Switching to \(chosen.displayName) will log you out and erase all local data for this server — including any inspections or issues that have not synced yet. You will need to log in again.")
}
}
}
@@ -242,18 +253,4 @@ struct SettingsView: View {
}
}
/// Delete every LocalIssue that has ever been assigned a serverId.
/// This covers two categories:
/// 1. Server-pulled assigned issues (inspectionLocalId == "", syncStatus == "synced")
/// 2. Inspector-created issues that already synced (inspectionLocalId != "", serverId != nil)
/// their serverIds are meaningless on a different server, so they must go too.
/// The only records preserved are truly pending device-created issues
/// (serverId == nil, syncStatus == "pending") that have never reached any server.
private func clearServerPulledData() {
let allIssues = (try? context.fetch(FetchDescriptor<LocalIssue>())) ?? []
allIssues
.filter { $0.serverId != nil }
.forEach { context.delete($0) }
try? context.save()
}
}