Decide complication pushes from the next appointment's identity
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
50446c8de5
commit
2e9989eab9
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
|
||||
/// Identifies the appointment a complication is currently showing.
|
||||
///
|
||||
/// The start date is part of the identity on purpose: a moved event keeps its
|
||||
/// id, and the complication is wrong until it is told.
|
||||
public struct NextEventIdentity: Equatable, Sendable, Codable {
|
||||
public let id: String
|
||||
public let start: Date
|
||||
|
||||
public init(id: String, start: Date) {
|
||||
self.id = id
|
||||
self.start = start
|
||||
}
|
||||
}
|
||||
|
||||
public enum WatchPushPolicy {
|
||||
/// The first event that has not ended yet — which is what every "next
|
||||
/// appointment" complication renders, including one that is running now.
|
||||
public static func nextEventIdentity(in snapshot: CalendarrSnapshot,
|
||||
at now: Date) -> NextEventIdentity? {
|
||||
snapshot.events
|
||||
.filter { $0.end > now }
|
||||
.min { $0.start < $1.start }
|
||||
.map { NextEventIdentity(id: $0.id, start: $0.start) }
|
||||
}
|
||||
|
||||
/// Whether this change is worth one of the day's limited complication
|
||||
/// pushes. Only a changed next appointment is — everything else reaches the
|
||||
/// watch on the next application-context delivery.
|
||||
public static func shouldPushComplicationUpdate(previous: NextEventIdentity?,
|
||||
current: NextEventIdentity?) -> Bool {
|
||||
previous != current
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user