findfamily-ios: share only via invite link, accept via hardcoded ID
- Commit
3417b3d57ca05219d1c61a724f570be558aad046- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 01:43 UTC (4 days ago)
- Parents
5e684b0
Split the conflated Add Person dialog into two dialogs so sharing location happens only through an invite link. ShareInviteDialog, opened from the FAB (renamed Share Invite), shows only the owner's own FindFamily ID as plain text and the share invite link button. AcceptPersonDialog, opened only from an invite deep link or an inbound sharing request, shows only the contact's hardcoded non-editable pre-filled ID, the contact's name (stored row name, falling back to the ID-based name used for inbound requests), and the Request Location button, which runs the same connect-time peer crypto check and upserts the user as AWAITING_RESPONSE, or MUTUAL_CONNECTION when accepting an inbound request. Removed share/accept paths: tap-to-copy my ID (code-based sharing), the editable Contact's FindFamily ID text field (manual code entry), and the contact picker (name/photo) inside the old dialog. Removed the now-unused strings addPersonAccept, addPersonAwaitingRequest, addPersonSelf, addPersonAlreadyMutual and addPersonAlreadyRequested, and renamed fabPerson to fabShareInvite. The contact picker remains only in the user detail panel for renaming an existing connection, outside any share or accept dialog. Temporary web-view links are link-based sharing and are unchanged. Protocol compatibility is unchanged: Networking.inviteLink() still builds https://ma.vayunmathur.com/ff/share#id=<Base26>&k= <fingerprint>, DeepLinkRouter still parses findfamily://add/<Base26>?k=<fingerprint>, and the fingerprint check in peerCryptoStatus still gates the accept submit. No Networking, Crypto, or Database code was touched. Dialog content and request behaviour are pinned by pure models in DialogModels.swift (ShareInviteDialogModel / AcceptPersonDialogModel) and by ShareAcceptDialogTests. Verified with xtool dev build on Linux (build complete) and a standalone Linux swiftc harness over DialogModels (all checks pass). swift test on this Linux box cannot build the iOS target (no SwiftUI module for the Linux target), so the XCTest suite runs on a Mac; that limitation is pre-existing.
Diff
apple/FindFamily/FindFamilyiOS/UI/BottomPanels.swift
diff --git a/apple/FindFamily/FindFamilyiOS/UI/BottomPanels.swift b/apple/FindFamily/FindFamilyiOS/UI/BottomPanels.swiftindex deb157a0c1..ac24c69f9a 100644--- a/apple/FindFamily/FindFamilyiOS/UI/BottomPanels.swift+++ b/apple/FindFamily/FindFamilyiOS/UI/BottomPanels.swift@@ -196,7 +196,7 @@ struct WaypointEditorPanel: View { // MARK: - Add menu (FAB) struct AddMenu: View {- let onAddPerson: () -> Void+ let onShareInvite: () -> Void let onAddWaypoint: () -> Void let onAddLink: () -> Void @@ -205,9 +205,9 @@ struct AddMenu: View { var body: some View { VStack(spacing: 12) { if expanded {- MenuButton(icon: "person.fill", text: Strings.fabPerson) {+ MenuButton(icon: "person.fill", text: Strings.fabShareInvite) { expanded = false- onAddPerson()+ onShareInvite() } MenuButton(icon: "mappin.and.ellipse", text: Strings.fabLocation) { expanded = false
apple/FindFamily/FindFamilyiOS/UI/DialogModels.swift
diff --git a/apple/FindFamily/FindFamilyiOS/UI/DialogModels.swift b/apple/FindFamily/FindFamilyiOS/UI/DialogModels.swiftnew file mode 100644index 0000000000..993bc4f081--- /dev/null+++ b/apple/FindFamily/FindFamilyiOS/UI/DialogModels.swift@@ -0,0 +1,88 @@+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 <code>`);+ /// 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+ )+ }+}
apple/FindFamily/FindFamilyiOS/UI/Dialogs.swift
diff --git a/apple/FindFamily/FindFamilyiOS/UI/Dialogs.swift b/apple/FindFamily/FindFamilyiOS/UI/Dialogs.swiftindex aca96815df..af4ef088a3 100644--- a/apple/FindFamily/FindFamilyiOS/UI/Dialogs.swift+++ b/apple/FindFamily/FindFamilyiOS/UI/Dialogs.swift@@ -1,85 +1,32 @@ import SwiftUI -// MARK: - AddPersonDialog+// MARK: - ShareInviteDialog -struct AddPersonDialog: View {- let presetID: Int64?- /// The `k=` fingerprint from the invite link that prefilled `presetID`, if any.- let fingerprint: String?+/// Sharing dialog. Location is shared only by sending an invite link, so+/// this shows only the owner's own FindFamily ID and the share-invite-link+/// button. No contact info, no copyable ID code, and no ID entry field.+struct ShareInviteDialog: View { @Binding var isPresented: Bool - @State private var theirIDStr: String = ""- @State private var contactName: String?- @State private var contactPhoto: String?- @State private var justCopied = false- @State private var showNeedsUpdate = false- @State private var showKeyMismatch = false-- private var myIDStr: String { Base26.encode(Networking.shared.userid) }-- private var theirID: Int64? {- if let preset = presetID { return preset }- return Base26.decode(theirIDStr)- }-- private var existingUser: User? {- guard let id = theirID else { return nil }- return Database.shared.user(id: id)- }-- private var status: RequestStatus? { existingUser?.requestStatus }-- private var statusMessage: (String, Bool)? {- guard let id = theirID else { return nil }- if id == Networking.shared.userid { return (Strings.addPersonSelf, true) }- guard let status = status else { return nil }- switch status {- case .awaitingRequest: return (Strings.addPersonAwaitingRequest, false)- case .mutualConnection: return (Strings.addPersonAlreadyMutual, true)- case .awaitingResponse: return (Strings.addPersonAlreadyRequested, true)- }- }-- private var submitEnabled: Bool {- guard let id = theirID, id != Networking.shared.userid,- let name = contactName, !name.isEmpty else { return false }- if let s = status, s == .mutualConnection || s == .awaitingResponse { return false }- return true- }-- private var submitLabel: String {- status == .awaitingRequest ? Strings.addPersonAccept : Strings.addPersonSubmit+ private var model: ShareInviteDialogModel {+ ShareInviteDialogModel(+ myIDString: Base26.encode(Networking.shared.userid),+ inviteLink: Networking.shared.inviteLink()+ ) } var body: some View { NavigationStack { Form { Section(Strings.addPersonYourID) {+ Text(model.myIDString).font(.body.monospaced())+ }+ Section {+ // Sends an https link that bounces to+ // findfamily://add/<myId>?k=<fingerprint>, which prefills the+ // recipient's accept dialog. See Networking.inviteLink(). Button {- copyMyID()- } label: {- HStack {- Text(myIDStr).font(.body.monospaced()).foregroundStyle(.primary)- Spacer()- Image(systemName: justCopied ? "checkmark" : "doc.on.doc")- .foregroundStyle(justCopied ? .green : .accentColor)- .contentTransition(.symbolEffect(.replace))- if justCopied {- Text("Copied")- .font(.caption)- .foregroundStyle(.green)- .transition(.opacity)- }- }- .contentShape(Rectangle())- }- .buttonStyle(.plain)- // Share sheet instead of copy/paste: sends an https link that bounces- // to findfamily://add/<myId>?k=<fingerprint>, which prefills the- // recipient's Add Person dialog. See Networking.inviteLink() for why- // the web hop exists and what `k` is.- Button {- Platform.share(Networking.shared.inviteLink())+ Platform.share(model.inviteLink) } label: { HStack { Image(systemName: "square.and.arrow.up")@@ -89,36 +36,55 @@ struct AddPersonDialog: View { .contentShape(Rectangle()) } }+ }+ .navigationTitle(Strings.shareInviteTitle)+ .toolbar {+ ToolbarItem(placement: .cancellationAction) {+ Button(Strings.cancelButton) { isPresented = false }+ }+ }+ }+ }+}++// MARK: - AcceptPersonDialog++/// Accept dialog for an invite link or inbound location-sharing request.+/// Shows only the contact's hardcoded (non-editable, pre-filled) ID, the+/// contact's name, and the request-location button.+struct AcceptPersonDialog: View {+ /// Hardcoded ID pre-filled from the invite link or inbound request.+ let presetID: Int64+ /// The `k=` fingerprint from the invite link that prefilled `presetID`, if any.+ let fingerprint: String?+ @Binding var isPresented: Bool++ @State private var showNeedsUpdate = false+ @State private var showKeyMismatch = false++ private var model: AcceptPersonDialogModel {+ let existing = Database.shared.user(id: presetID)+ return AcceptPersonDialogModel(+ contactID: presetID,+ existingName: existing?.name,+ existingPhoto: existing?.photo,+ existingStatus: existing?.requestStatus,+ myID: Networking.shared.userid+ )+ }++ var body: some View {+ NavigationStack {+ Form { Section(Strings.addPersonTheirID) {- if presetID != nil {- Text(Base26.encode(presetID!)).font(.body.monospaced())- } else {- TextField("ABCDE", text: $theirIDStr)- .textInputAutocapitalization(.characters)- .autocorrectionDisabled()- .font(.body.monospaced())- }- if let (msg, isError) = statusMessage {- Text(msg).font(.caption).foregroundStyle(isError ? .red : .secondary)- }+ Text(model.contactIDString).font(.body.monospaced()) } Section(Strings.addPersonName) {- Button {- Platform.presentContactPicker { name, photo in- contactName = name- contactPhoto = photo- }- } label: {- HStack {- Text(contactName ?? "Pick a contact").foregroundStyle(contactName == nil ? .secondary : .primary)- Spacer()- Image(systemName: "person.crop.circle")- }- }+ Text(model.contactName) } Section {- Button(submitLabel) { submit() }- .disabled(!submitEnabled)+ Button(Strings.addPersonSubmit) { submit() }+ .disabled(!model.requestEnabled) .frame(maxWidth: .infinity) } }@@ -142,19 +108,11 @@ struct AddPersonDialog: View { } private func submit() {- guard let id = theirID, let name = contactName else { return }- // Check the peer's post-quantum capability "when connecting". FindFamily is PQC-only, so a- // peer who registered only a classic key is on an outdated app: prompt them to update- // instead of adding them. Unknown (not-yet-registered) peers are allowed through — they may- // register with PQC once they install the app.- //- // The fingerprint only vouches for the id that arrived in the link, and the field is- // read-only whenever there is a preset, so it applies exactly when one is present.- let inviteFingerprint = presetID != nil ? fingerprint : nil+ let current = model Task { @MainActor in let check = await Networking.shared.peerCryptoStatus(- forUserid: id,- expectedFingerprint: inviteFingerprint+ forUserid: current.contactID,+ expectedFingerprint: fingerprint ) if check.status == .needsUpdate { showNeedsUpdate = true@@ -164,35 +122,10 @@ struct AddPersonDialog: View { showKeyMismatch = true return }- let isAccepting = (status == .awaitingRequest)- let newStatus: RequestStatus = isAccepting ? .mutualConnection : .awaitingResponse- let user = User(- id: id,- name: name,- photo: contactPhoto,- locationName: "Unknown Location",- sendingEnabled: true,- requestStatus: newStatus,- lastLocationChangeTime: Date(),- encryptionKey: nil,- // Store the fingerprint-checked key with the row itself, so the key that- // was verified is the one used from here on rather than a fresh lookup.- pqcEncryptionKey: check.verifiedBundleB64- )- Database.shared.upsertUser(user)+ Database.shared.upsertUser(current.makeUser(verifiedBundleB64: check.verifiedBundleB64, now: Date())) isPresented = false } }-- private func copyMyID() {- Platform.copy(myIDStr)- UINotificationFeedbackGenerator().notificationOccurred(.success)- withAnimation(.easeInOut(duration: 0.2)) { justCopied = true }- Task { @MainActor in- try? await Task.sleep(nanoseconds: 1_500_000_000)- withAnimation(.easeInOut(duration: 0.2)) { justCopied = false }- }- } } // MARK: - SecurityCodeView
apple/FindFamily/FindFamilyiOS/UI/MainView.swift
diff --git a/apple/FindFamily/FindFamilyiOS/UI/MainView.swift b/apple/FindFamily/FindFamilyiOS/UI/MainView.swiftindex bfb7cdfff1..420de902f1 100644--- a/apple/FindFamily/FindFamilyiOS/UI/MainView.swift+++ b/apple/FindFamily/FindFamilyiOS/UI/MainView.swift@@ -49,7 +49,8 @@ struct MainView: View { @State private var waypointCoord = Coord.zero // Dialogs- @State private var showAddPersonDialog = false+ @State private var showShareInviteDialog = false+ @State private var showAcceptPersonDialog = false @State private var addPersonId: Int64? /// Fingerprint from the invite link that set `addPersonId`, when it came from one. @State private var addPersonFingerprint: String?@@ -113,15 +114,20 @@ struct MainView: View { .navigationTitle(Text(headerTitle)) .navigationBarTitleDisplayMode(.inline) .toolbar { topBarToolbar }- .sheet(isPresented: $showAddPersonDialog, onDismiss: {+ .sheet(isPresented: $showShareInviteDialog) {+ ShareInviteDialog(isPresented: $showShareInviteDialog)+ }+ .sheet(isPresented: $showAcceptPersonDialog, onDismiss: { addPersonId = nil addPersonFingerprint = nil }) {- AddPersonDialog(- presetID: addPersonId,- fingerprint: addPersonFingerprint,- isPresented: $showAddPersonDialog- )+ if let presetID = addPersonId {+ AcceptPersonDialog(+ presetID: presetID,+ fingerprint: addPersonFingerprint,+ isPresented: $showAcceptPersonDialog+ )+ } } .sheet(isPresented: $showAddLinkDialog) { AddLinkDialog(isPresented: $showAddLinkDialog)@@ -152,12 +158,12 @@ struct MainView: View { animateToCoord = wp.coord } }- // A tapped findfamily://add/<id> invite prefills the Add Person dialog. @Published+ // A tapped findfamily://add/<id> invite prefills the accept dialog. @Published // replays its current value on subscribe, so this catches cold-start links too. .onReceive(deepLink.$pendingAddInvite.compactMap { $0 }) { invite in addPersonId = invite.id addPersonFingerprint = invite.fingerprint- showAddPersonDialog = true+ showAcceptPersonDialog = true deepLink.pendingAddInvite = nil } }@@ -207,10 +213,8 @@ struct MainView: View { private var addFAB: some View { if selectedUserId == nil && selectedWaypointId == nil { AddMenu(- onAddPerson: {- addPersonId = nil- addPersonFingerprint = nil- showAddPersonDialog = true+ onShareInvite: {+ showShareInviteDialog = true }, onAddWaypoint: { selectedWaypointId = 0@@ -302,7 +306,7 @@ struct MainView: View { // no fingerprint to check against. addPersonId = id addPersonFingerprint = nil- showAddPersonDialog = true+ showAcceptPersonDialog = true } ) }
apple/FindFamily/FindFamilyiOS/Util/Util.swift
diff --git a/apple/FindFamily/FindFamilyiOS/Util/Util.swift b/apple/FindFamily/FindFamilyiOS/Util/Util.swiftindex 10f0a335db..6de8a4e31c 100644--- a/apple/FindFamily/FindFamilyiOS/Util/Util.swift+++ b/apple/FindFamily/FindFamilyiOS/Util/Util.swift@@ -18,7 +18,7 @@ enum Strings { static let sectionLocationSharingRequests = "Location Sharing Requests" static let sectionTemporaryLinks = "Temporary Links" static let sectionSavedPlaces = "Saved Places"- static let fabPerson = "Add Person"+ static let fabShareInvite = "Share Invite" static let fabLocation = "Add Place" static let fabLink = "Add Link" @@ -77,12 +77,8 @@ enum Strings { static let addPersonTheirID = "Contact's FindFamily ID" static let addPersonName = "Contact's Name" static let addPersonSubmit = "Request Location"- static let addPersonAccept = "Accept Location Request" static let shareInviteLink = "Share invite link"- static let addPersonAwaitingRequest = "This person has requested your location"- static let addPersonSelf = "Cannot share your location with yourself"- static let addPersonAlreadyMutual = "Already sharing location with this person"- static let addPersonAlreadyRequested = "Already requested to share with this person"+ static let shareInviteTitle = "Share Invite" static let backupExport = "Export Backup" static let backupImport = "Import Backup"
apple/FindFamily/Package.swift
diff --git a/apple/FindFamily/Package.swift b/apple/FindFamily/Package.swiftindex 84ecd02afd..1a16e6aba1 100644--- a/apple/FindFamily/Package.swift+++ b/apple/FindFamily/Package.swift@@ -26,5 +26,10 @@ let package = Package( .swiftLanguageMode(.v5), ] ),+ .testTarget(+ name: "FindFamilyTests",+ dependencies: ["FindFamily"],+ path: "Tests/FindFamilyTests"+ ), ] )
apple/FindFamily/Tests/FindFamilyTests/ShareAcceptDialogTests.swift
diff --git a/apple/FindFamily/Tests/FindFamilyTests/ShareAcceptDialogTests.swift b/apple/FindFamily/Tests/FindFamilyTests/ShareAcceptDialogTests.swiftnew file mode 100644index 0000000000..8af1e2adc5--- /dev/null+++ b/apple/FindFamily/Tests/FindFamilyTests/ShareAcceptDialogTests.swift@@ -0,0 +1,104 @@+import XCTest+@testable import FindFamily++final class ShareAcceptDialogTests: XCTestCase {++ // MARK: - Share dialog++ func testShareDialogShowsOnlyMyIDAndShareInviteLinkButton() {+ let model = ShareInviteDialogModel(+ myIDString: "ABCDE",+ inviteLink: "https://ma.vayunmathur.com/ff/share#id=ABCDE&k=abc-123_"+ )+ XCTAssertEqual(model.presentedFields, [.myID, .shareInviteLinkButton])+ XCTAssertEqual(model.myIDString, "ABCDE")+ XCTAssertFalse(model.showsContactInfo)+ }++ func testShareDialogInviteLinkShapeIsUnchanged() {+ // Same link shape as before the strip: https bounce page, id and+ // fingerprint in the fragment. Android builds the identical shape.+ let link = "https://ma.vayunmathur.com/ff/share#id=ABCDE&k=abc-123_"+ let model = ShareInviteDialogModel(myIDString: "ABCDE", inviteLink: link)+ XCTAssertEqual(model.inviteLink, link)+ XCTAssertTrue(model.inviteLink.hasPrefix("https://"))+ XCTAssertTrue(model.inviteLink.contains("#id=ABCDE"))+ XCTAssertTrue(model.inviteLink.contains("&k="))+ }++ // MARK: - Accept dialog++ func testAcceptDialogIDIsHardcodedPrefilledAndNotEditable() {+ let model = AcceptPersonDialogModel(+ contactID: 12345, existingName: "Ada", existingPhoto: nil,+ existingStatus: nil, myID: 999+ )+ XCTAssertFalse(model.isIDEditable)+ XCTAssertEqual(model.contactID, 12345)+ XCTAssertEqual(model.contactIDString, Base26.encode(12345))+ XCTAssertEqual(model.presentedFields, [.contactID, .contactName, .requestLocationButton])+ XCTAssertFalse(model.showsContactPicker)+ XCTAssertFalse(model.showsMyID)+ XCTAssertFalse(model.showsShareInviteLinkButton)+ }++ func testAcceptDialogShowsContactName() {+ let named = AcceptPersonDialogModel(+ contactID: 7, existingName: "Ada Lovelace", existingPhoto: "photo",+ existingStatus: .awaitingRequest, myID: 999+ )+ XCTAssertEqual(named.contactName, "Ada Lovelace")++ // No stored row (fresh invite link): fall back to the ID-based name+ // used for inbound requests, never an editable/contact-picked name.+ let unnamed = AcceptPersonDialogModel(+ contactID: 7, existingName: nil, existingPhoto: nil,+ existingStatus: nil, myID: 999+ )+ XCTAssertEqual(unnamed.contactName, "ID \(Base26.encode(7))")+ }++ func testRequestButtonIssuesLocationRequest() {+ let model = AcceptPersonDialogModel(+ contactID: 42, existingName: "Grace", existingPhoto: nil,+ existingStatus: nil, myID: 999+ )+ XCTAssertTrue(model.requestEnabled)+ XCTAssertEqual(model.resultingStatus, .awaitingResponse)++ let user = model.makeUser(verifiedBundleB64: "bundle", now: Date(timeIntervalSince1970: 0))+ XCTAssertEqual(user.id, 42)+ XCTAssertEqual(user.name, "Grace")+ XCTAssertEqual(user.requestStatus, .awaitingResponse)+ XCTAssertTrue(user.sendingEnabled)+ XCTAssertEqual(user.pqcEncryptionKey, "bundle")+ }++ func testRequestButtonAcceptsInboundRequestAsMutual() {+ let model = AcceptPersonDialogModel(+ contactID: 42, existingName: "Grace", existingPhoto: nil,+ existingStatus: .awaitingRequest, myID: 999+ )+ XCTAssertTrue(model.requestEnabled)+ XCTAssertEqual(model.resultingStatus, .mutualConnection)+ XCTAssertEqual(+ model.makeUser(verifiedBundleB64: nil, now: Date()).requestStatus,+ .mutualConnection+ )+ }++ func testRequestButtonDisabledForSelfAndExistingConnections() {+ XCTAssertFalse(AcceptPersonDialogModel(+ contactID: 999, existingName: "Me", existingPhoto: nil,+ existingStatus: nil, myID: 999+ ).requestEnabled)+ XCTAssertFalse(AcceptPersonDialogModel(+ contactID: 42, existingName: "Grace", existingPhoto: nil,+ existingStatus: .mutualConnection, myID: 999+ ).requestEnabled)+ XCTAssertFalse(AcceptPersonDialogModel(+ contactID: 42, existingName: "Grace", existingPhoto: nil,+ existingStatus: .awaitingResponse, myID: 999+ ).requestEnabled)+ }+}