// Cotton Chat's notifications, as the app delegate reaches them. // // The delegate (`CottonAppDelegate`) is every app's and sits below the chat // engine (`CottonChat`), which only Messages carries. So the engine fills // these at launch and the delegate hands over what is the chat's: a response // to a chat notification (a tap, Reply, Mark as read, Call back) and a // background push with chat news (the Worker's read nudge, // `{ aps: { content-available: 1 }, chat: 1, read: 1 }`). Nil in an app // that carries no chat: the delegate goes on as before. import CottonKit import Foundation /// One response to a chat notification, in values a test can write. public struct ChatNotificationResponse: Equatable, Sendable { /// `UNNotificationDefaultActionIdentifier` for a tap, else the action's /// (`ChatNoticeNames`). public var action: String /// The notification's `userInfo`. public var userInfo: JSONValue /// What was written in Reply's box. public var text: String? /// The notification's own identifier. public var identifier: String public init(action: String, userInfo: JSONValue, text: String?, identifier: String) { self.action = action self.userInfo = userInfo self.text = text self.identifier = identifier } } @MainActor public enum ChatNotificationHooks { /// A response to one of the chat's notifications, answered before the /// delegate tells iOS it is done. public static var respond: (@MainActor (ChatNotificationResponse) async -> Void)? /// A background push with chat news: what waits is landed and the /// notifications made to match; true when it was asked. public static var woke: (@MainActor () async -> Bool)? /// A missed call's Call back (`chat.call { call }`), filled by the call /// engine where one runs. public static var callBack: (@MainActor (String) -> Void)? /// Whether a notification or push is the chat's: the Worker's and the /// app's own all carry `chat`. public nonisolated static func isChat(_ userInfo: JSONValue) -> Bool { userInfo["chat"] != nil } }