Cotton code
46 lines · 1.9 KB · SwiftRaw
import CottonValuesimport Foundation/// This phone met a Cotton push: the receipt `device.pushAck` carries to the/// serving Mac.////// A push counts as reaching the owner when the PHONE says it showed it, not/// when Apple answers 2xx (architect, 12 Oct 2026): two Test pushes Apple/// took on 12 Oct never showed, because iOS had never been asked for/// notifications on that install and dropped every alert. The receipt is/// what the first-push stamp and Test push's "Arrived" stand on.public struct PushReceipt: Encodable, Sendable, Equatable {    /// The push's own id — the payload's `notificationId`, the `_push_log`    /// row the server sent it from and the `apns-id` Apple traces it by.    public let pushId: String    /// When iOS delivered it, ISO-8601 UTC (`UNNotification.date`).    public let receivedAt: String    /// How the phone met it.    public let how: How    public enum How: String, Encodable, Sendable {        /// Presented while the app was open (`willPresent`).        case shown        /// Found in Notification Centre at a foreground — iOS showed it while        /// the app was away.        case delivered        /// The person tapped it (`didReceive`).        case opened    }    public init(pushId: String, receivedAt: String, how: How) {        self.pushId = pushId        self.receivedAt = receivedAt        self.how = how    }    /// The receipt of a notification, or nil for one that is not a server    /// push — a local reminder carries no `notificationId`, and nothing    /// is owed for it.    public static func of(userInfo: JSONValue, date: Date, how: How) -> PushReceipt? {        guard let id = NotificationRoutes.stringParam(NotificationTaps.payload(of: userInfo), "notificationId") else {            return nil        }        return PushReceipt(pushId: id, receivedAt: CottonDate.format(date), how: how)    }}