// What this phone knows about itself, and the one call that tells the// server to forget it.//// **`deviceId` is `identifierForVendor`**, the value the previous build// registered under, so a forget names the same row.importFoundation#if canImport(UIKit)import UIKit#endif/// What this phone knows about itself, at registration time.publicstructDeviceFacts: Equatable, Sendable {/// `identifierForVendor`. See the file header.publiclet deviceId: String/// The `apns-topic` every push to this device carries.publiclet bundleId: Stringpubliclet appVersion: String?publiclet build: String?publiclet locale: String?publiclet timezone: String?publicinit( deviceId: String, bundleId: String, appVersion: String? = nil, build: String? = nil, locale: String? = nil, timezone: String? = nil ) {self.deviceId = deviceIdself.bundleId = bundleIdself.appVersion = appVersionself.build = buildself.locale = localeself.timezone = timezone }}/// Where the facts come from — a seam, so a test names them.////// **`@MainActor`, because `UIDevice.current` is.** The vendor identifier is/// UIKit's and UIKit is main-actor-isolated; the only caller is/// `NotificationsModel`, which is `@MainActor` already, so this is a/// compile-time fact rather than a `MainActor.assumeIsolated` that would trap/// at runtime to say the same thing.@MainActorpublicprotocolDeviceFactsSource: Sendable {/// `nil` when the vendor identifier is unavailable, which iOS allows while/// the device is locked and just after a restore. There is nothing to/// register without it, and the next foreground asks again.func read() -> DeviceFacts?}/// The real one.publicstructSystemDeviceFacts: DeviceFactsSource {publicinit() {}publicfunc read() -> DeviceFacts? { #if canImport(UIKit)guardlet vendor = UIDevice.current.identifierForVendor?.uuidString else { returnnil }let info = Bundle.main.infoDictionaryreturnDeviceFacts( deviceId: vendor, bundleId: Bundle.main.bundleIdentifier ?? "",// The label with its build, "1.0.0 (256)" — the marketing// version alone does not say which build a phone runs. appVersion: CottonConfig.bundleVersionLabel, build: info?["CFBundleVersion"] as? String, locale: Locale.current.identifier, timezone: TimeZone.current.identifier ) #else// No vendor identifier on the Mac, and no push registration either —// the Mac is a server, not a device that is pushed to.returnnil #endif }}/// The one call.publicenumPushRegistrar {/// Tell the server to forget this device.////// **Answers either way and never throws**, on every path — the crate's own/// contract, and this side does not add one. Called before a leave and/// before sign-out: a person handing back a phone must never be trapped by/// a deregistration that could not reach the server.publicstaticfunc forget( deviceId: String, through core: any CottonCalling ) async -> PushForgotten {do {returntryawait core.call(CottonMethod.pushForget,PushForget(deviceId: deviceId),as: PushForgotten.self ) } catchlet refusal asCottonCallError {// The crate answers rather than refusing, so reaching here means// the BOUNDARY refused — an `unknown_method` on a build without the// crate half, say. Same shape either way: the caller says nothing// and moves on.returnPushForgotten(forgotten: false, reason: refusal.code) } catch {returnPushForgotten(forgotten: false, reason: "unreadable") } }}