import Foundation // MARK: - Share invite dialog model /// Content of the share dialog. Sharing location happens only by sending an /// invite link, so the dialog presents exactly two things: the owner's own /// FindFamily ID and the share-invite-link button. There is no contact info, /// no copyable ID code, and no field for entering another person's ID. enum ShareDialogField: Equatable { case myID case shareInviteLinkButton } struct ShareInviteDialogModel: Equatable { let myIDString: String let inviteLink: String var presentedFields: [ShareDialogField] { [.myID, .shareInviteLinkButton] } var showsContactInfo: Bool { false } } // MARK: - Accept / request dialog model /// Content of the accept dialog, shown only for an ID that arrived from an /// invite link or an inbound location-sharing request. The ID is hardcoded /// from that source and is never editable; the only other content is the /// contact's name and the request-location button. enum AcceptDialogField: Equatable { case contactID case contactName case requestLocationButton } struct AcceptPersonDialogModel: Equatable { /// Hardcoded ID from the invite link or inbound request. let contactID: Int64 let existingName: String? let existingPhoto: String? let existingStatus: RequestStatus? let myID: Int64 /// The ID field is pre-filled from the link/request and never editable. var isIDEditable: Bool { false } var contactIDString: String { Base26.encode(contactID) } /// Existing rows carry a name (inbound requests are named `ID `); /// a fresh invite has no row yet, so fall back to that same convention. var contactName: String { if let name = existingName, !name.isEmpty { return name } return "ID \(contactIDString)" } var presentedFields: [AcceptDialogField] { [.contactID, .contactName, .requestLocationButton] } var showsContactPicker: Bool { false } var showsMyID: Bool { false } var showsShareInviteLinkButton: Bool { false } var isSelf: Bool { contactID == myID } var requestEnabled: Bool { guard !isSelf else { return false } if existingStatus == .mutualConnection || existingStatus == .awaitingResponse { return false } return true } /// Accepting an inbound request completes the mutual connection; /// otherwise this issues a new location request. var resultingStatus: RequestStatus { existingStatus == .awaitingRequest ? .mutualConnection : .awaitingResponse } /// The row issued by the request button. `verifiedBundleB64` is the /// fingerprint-checked key from the connect-time check, pinned on the /// row so the verified key is the one used from here on. func makeUser(verifiedBundleB64: String?, now: Date) -> User { User( id: contactID, name: contactName, photo: existingPhoto, locationName: "Unknown Location", sendingEnabled: true, requestStatus: resultingStatus, lastLocationChangeTime: now, encryptionKey: nil, pqcEncryptionKey: verifiedBundleB64 ) } }