fix(visibility): auto-reconcile server sidebar_hidden on launch/resume/sync

Hiding or showing a calendar on the web sets enabled=false + sidebar_hidden
server-side, so the server stops returning that calendar's events entirely.
The app only reconciled these per-calendar flags when the filter sheet or the
accounts screen happened to be opened — never on launch, resume or the
periodic pull. So a calendar re-enabled on the web stayed invisible (still
banished locally, and its events weren't in the cache) until a manual sync or
relaunch — the "hide it on the web and the app won't bring it back" bug.

Add CalendarStore.reconcileCalendarVisibility(api:) which pulls the account
lists, updates the banished set from the server's sidebar_hidden flags, and
returns whether anything changed. CalendarHostView now runs it (via
syncFromServer) on launch, on scenePhase .active, in the periodic loop, and on
manual sync — forcing a refetch when the set changed so a re-enabled calendar's
events actually reappear without user intervention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-03 22:04:58 +02:00
parent 61237134f0
commit 325f357357
2 changed files with 52 additions and 5 deletions

View File

@@ -225,6 +225,38 @@ class CalendarStore {
publishWidgetSnapshot()
}
/// Reconcile the local "banished" set with the server's per-calendar
/// `sidebar_hidden` flags (server wins for CalDAV / Google / HA). Returns
/// `true` if the set changed, so the caller can force a refetch.
///
/// This closes the sync gap where hiding/showing a calendar on the web (or
/// another device) was only ever picked up when the filter sheet or the
/// accounts screen happened to be opened not on app launch / resume. A
/// calendar re-enabled on the web has NO events in the cache (the server
/// excludes a hidden calendar's events entirely), so a plain
/// `refreshFromCache` can't bring them back: the caller must force a reload.
func reconcileCalendarVisibility(api: CalendarrAPI) async -> Bool {
async let c = (try? await api.getCalDAVAccounts()) ?? []
async let g = (try? await api.getGoogleAccounts()) ?? []
async let h = (try? await api.getHomeAssistantAccounts()) ?? []
let (caldav, google, ha) = await (c, g, h)
var b = banishedCalendarKeys
func applyServerHidden(_ source: String, _ id: Int, _ hidden: Bool) {
let key = Self.calendarKey(source: source, calendarId: "\(id)")
if hidden { b.insert(key) } else { b.remove(key) }
}
for acc in caldav { for cal in acc.calendars ?? [] { applyServerHidden("caldav", cal.id, cal.sidebarHidden) } }
for acc in google { for cal in acc.calendars ?? [] { applyServerHidden("google", cal.id, cal.sidebarHidden) } }
for acc in ha { for cal in acc.calendars ?? [] { applyServerHidden("homeassistant", cal.id, cal.sidebarHidden) } }
guard b != banishedCalendarKeys else { return false }
banishedCalendarKeys = b
Self.saveBanishedKeys(b)
NotificationCenter.default.post(name: .banishedCalendarsChanged, object: nil)
return true
}
// MARK: Reminder-disabled-calendar persistence
private static let reminderDisabledKeysDefaultsKey = "reminderDisabledCalendarKeys"