import Foundation /// Open-only routing for default taps, old payloads and Live Activities. Read from /// the alert's `equipo` object (wire.PushData) or the app's own link. public enum PushRoute: Equatable, Sendable { /// A card waits on you: the conversation, at that card. case card(String) /// The coordinator replied: the conversation. case conversation /// A task finished, stopped or is running: the task view. case task(String) /// The alert's routing data; nil for a badge, or anything unknown. public init?(userInfo: [AnyHashable: Any]) { guard let data = userInfo["equipo"] as? [String: Any], let kind = data["kind"] as? String else { return nil } func id(_ key: String) -> String? { (data[key] as? String).flatMap { $0.isEmpty ? nil : $0 } } switch kind { case "card": // A card the device cannot place still opens beside its task. if let card = id("card_id") { self = .card(card) } else if let task = id("task_id") { self = .task(task) } else { return nil } case "reply": self = .conversation case "task": guard let task = id("task_id") else { return nil } self = .task(task) default: return nil } } /// A Live Activity's link (EquipoLink). public init?(url: URL) { guard let task = EquipoLink.taskID(from: url) else { return nil } self = .task(task) } /// The screen it opens. public var destination: Destination { switch self { case .card(let id): return Destination(pane: .conversation, cardID: id) case .conversation: return Destination(pane: .conversation) case .task(let id): return Destination(pane: .tasks, taskID: id) } } } /// A screen in the app: a pane (a tab on iPhone, the sidebar on the Mac), /// and the card to bring into view or the task to open in it. public struct Destination: Equatable, Sendable { public enum Pane: Hashable, Sendable { case conversation, needs, tasks, projects } public var pane: Pane public var cardID: String? public var taskID: String? public var projectID: String? public var macAction: MacTaskAction? public var focusComposer: Bool public init(pane: Pane, cardID: String? = nil, taskID: String? = nil, projectID: String? = nil, focusComposer: Bool = false, macAction: MacTaskAction? = nil) { self.pane = pane; self.cardID = cardID; self.taskID = taskID; self.projectID = projectID; self.focusComposer = focusComposer; self.macAction = macAction } }