import Foundation /// A push notification as the app reads it. /// /// `instance` and `user` name the account the notice belongs to. One /// device token is one install, and an install registers against every /// account signed in on it, so `path` alone is ambiguous — two /// instances can hold the same `owner/name`. nonisolated struct PushPayload: Equatable, Sendable { let instance: URL let user: String let path: String /// The recipient's unread count, for the app icon badge. Absent on /// a notification from a server that predates it. let badge: Int init?(userInfo: [AnyHashable: Any]) { guard let raw = userInfo["instance"] as? String, let instance = URL(string: raw), instance.scheme != nil, let user = userInfo["user"] as? String, !user.isEmpty, let path = userInfo["path"] as? String, !path.isEmpty else { return nil } self.instance = instance self.user = user self.path = path self.badge = (userInfo["aps"] as? [AnyHashable: Any])?["badge"] as? Int ?? 0 } }