import Foundation /// A tapped notification resolved against the accounts signed in on /// this device: which account it belongs to, and the screen it opens. nonisolated struct PushTarget: Equatable, Sendable { let accountID: String let destination: NotificationDestination /// Nil when no signed-in account matches — you signed out of it — /// or when the path names nothing the app can route to. init?(payload: PushPayload, accounts: [Account]) { guard let destination = notificationDestination(forPath: payload.path) else { return nil } // Run the payload's instance through the same normalisation an // account's did (trailing slash, default port) rather than // comparing raw URLs, which a server's unnormalised config can // make unequal even when they name the same instance. guard let instance = try? GitbayInstance(url: payload.instance.absoluteString) else { return nil } // Both sides, not just the payload's: an account stored before // the constructor folded the default port still holds an // explicit ":443". Normalising is for the comparison only — // rewriting what is stored would change `Account.id` and orphan // the Keychain token it keys. let match = accounts.first { $0.username == payload.user && (try? GitbayInstance(url: $0.instance.baseURL.absoluteString))?.baseURL == instance.baseURL } guard let match else { return nil } self.accountID = match.id self.destination = destination } }