Docs native S2a: each document window derives its team name
The subtitle's team came from a map the home window filled when it appeared, so a window opened before it, or a renamed team, showed no name or a stale one (Fable on #169, finding 9). A document window now asks the Oficina ID session for its account's team each time it draws (the signed-in team, or another team of the identity from its teams cache); a server account's name still comes from the home window's account list, now kept current when that list changes. SignedInLaunchTests covers the derived name with no home window, an unknown team, and a server account.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+40
−2
native/apple/Sources/DocsApp/DocsAccountWindow.swift+1 −0native/apple/Sources/DocsApp/DocsApp.swift+1 −1native/apple/Sources/DocsApp/DocsDocumentWindow.swift+10 −1native/apple/Sources/DocsKit/DocsOficinaID.swift+11 −0native/apple/Tests/DocsWindowTests/SignedInLaunchTests.swift+17 −0
diff --git a/native/apple/Sources/DocsApp/DocsAccountWindow.swift b/native/apple/Sources/DocsApp/DocsAccountWindow.swift| index 4560b4e..2b68590 100644 |
| --- a/native/apple/Sources/DocsApp/DocsAccountWindow.swift |
| +++ b/native/apple/Sources/DocsApp/DocsAccountWindow.swift |
| @@ -308,6 +308,7 @@ struct DocsAccountWindow: View { |
| }) |
| .id(account) |
| .onAppear { windows.teamNames[account] = connection.accounts.first { $0.id == account }?.name } |
| + .onChange(of: connection.accounts) { _, accounts in windows.teamNames[account] = accounts.first { $0.id == account }?.name } |
| } |
| #else |
| DocsWorkspace(client: client, accountID: connection.activeAccountID, transport: transport(for: connection.activeAccountID), accounts: connection.showAccounts, signOut: connection.signOut) |
diff --git a/native/apple/Sources/DocsApp/DocsApp.swift b/native/apple/Sources/DocsApp/DocsApp.swift| index 8941857..4c37412 100644 |
| --- a/native/apple/Sources/DocsApp/DocsApp.swift |
| +++ b/native/apple/Sources/DocsApp/DocsApp.swift |
| @@ -58,7 +58,7 @@ import SwiftUI |
| #endif |
| } |
| WindowGroup(docsMacString("Docs"), id: "document", for: UUID.self) { $id in |
| - DocsDocumentWindow(windows: windows, id: id) |
| + DocsDocumentWindow(windows: windows, oficina: oficina, id: id) |
| } |
| .defaultSize(width: 1120, height: 820) |
| .restorationBehavior(.disabled) |
diff --git a/native/apple/Sources/DocsApp/DocsDocumentWindow.swift b/native/apple/Sources/DocsApp/DocsDocumentWindow.swift| index a7c1152..bf6377a 100644 |
| --- a/native/apple/Sources/DocsApp/DocsDocumentWindow.swift |
| +++ b/native/apple/Sources/DocsApp/DocsDocumentWindow.swift |
| @@ -4,6 +4,8 @@ import SwiftUI |
| struct DocsDocumentWindow: View { |
| let windows: DocsWindows |
| + /// For the subtitle's team, derived per window (spec D7). |
| + @ObservedObject var oficina: DocsOficinaSession |
| let id: UUID? |
| @Environment(\.openWindow) private var openWindow |
| var body: some View { |
| @@ -13,7 +15,7 @@ struct DocsDocumentWindow: View { |
| // Open a document… (⌘K) opens or focuses that document's window. |
| let id = windows.reserve(account: entry.account, document: document, title: title, client: entry.client) |
| openWindow(id: "document", value: id) |
| - }, team: windows.teamNames[entry.account]) |
| + }, team: Self.team(for: entry.account, oficina: oficina, windows: windows)) |
| .id(entry.id) |
| .focusedSceneValue(\.docsWindowAccount, entry.account) |
| .onAppear { windows.setOpen(entry.id, true) } |
| @@ -24,5 +26,12 @@ struct DocsDocumentWindow: View { |
| } |
| } |
| } |
| + /// An Oficina ID team's name from the identity's own record, so a |
| + /// renamed team or a window opened before the home window shows the |
| + /// right one; a server account's from the home window's account list. |
| + @MainActor static func team(for account: String, oficina: DocsOficinaSession, windows: DocsWindows) -> String? { |
| + if DocsOficinaSession.isOficinaAccount(account) { return oficina.teamName(forAccount: account) ?? windows.teamNames[account] } |
| + return windows.teamNames[account] |
| + } |
| } |
| #endif |
diff --git a/native/apple/Sources/DocsKit/DocsOficinaID.swift b/native/apple/Sources/DocsKit/DocsOficinaID.swift| index 6047bef..ba3357d 100644 |
| --- a/native/apple/Sources/DocsKit/DocsOficinaID.swift |
| +++ b/native/apple/Sources/DocsKit/DocsOficinaID.swift |
| @@ -170,6 +170,17 @@ public enum DocsSignInRoute: String, Sendable { |
| accountID(identity: state.identity.id, team: state.team.sqid) |
| } |
| + /// The team name a document window of `account` shows in its subtitle |
| + /// (spec D7): the signed-in team's, or another team of the same identity |
| + /// from the teams cache, read each time so a renamed team shows its new |
| + /// name. nil for a server account or a team this device has not seen. |
| + public func teamName(forAccount account: String) -> String? { |
| + guard let state = mounted ?? signedIn else { return nil } |
| + if Self.accountID(state) == account { return state.team.name } |
| + return model.store.teams(state.identity.id)?.teams |
| + .first { Self.accountID(identity: state.identity.id, team: $0.sqid) == account }?.name |
| + } |
| + |
| nonisolated public static func accountID(identity: String, team: String) -> String { |
| prefix + component(identity) + "." + component(team) |
| } |
diff --git a/native/apple/Tests/DocsWindowTests/SignedInLaunchTests.swift b/native/apple/Tests/DocsWindowTests/SignedInLaunchTests.swift| index 8e10f4d..7a9f9e9 100644 |
| --- a/native/apple/Tests/DocsWindowTests/SignedInLaunchTests.swift |
| +++ b/native/apple/Tests/DocsWindowTests/SignedInLaunchTests.swift |
| @@ -126,6 +126,23 @@ import RastrilloTestSupport |
| XCTAssertEqual(docs.mounted, mounted, "still signed in to the same team") |
| } |
| + /// The subtitle's team comes from the identity's own record for each |
| + /// document window, not from the home window having appeared (Fable on |
| + /// #169, finding 9). |
| + func testADocumentWindowsTeamNameIsDerivedFromItsAccount() async throws { |
| + let docs = try await signedInSession() |
| + let mounted = try XCTUnwrap(docs.mounted) |
| + let account = DocsOficinaSession.accountID(mounted) |
| + let windows = DocsWindows() |
| + XCTAssertTrue(windows.teamNames.isEmpty, "no home window has appeared") |
| + XCTAssertEqual(DocsDocumentWindow.team(for: account, oficina: docs, windows: windows), "Paul") |
| + let other = DocsOficinaSession.accountID(identity: mounted.identity.id, team: "unknown-team") |
| + XCTAssertNil(DocsDocumentWindow.team(for: other, oficina: docs, windows: windows), "a team never seen: the state alone") |
| + let server = UUID().uuidString |
| + windows.teamNames[server] = "Tito's server" |
| + XCTAssertEqual(DocsDocumentWindow.team(for: server, oficina: docs, windows: windows), "Tito's server") |
| + } |
| + |
| /// Docs' real home window, shown, with a way to let it run. |
| private func show(_ docs: DocsOficinaSession, _ windows: DocsWindows) -> (window: NSWindow, pump: (Double) async -> Void) { |
| let host = NSHostingView(rootView: DocsAccountWindow(oficina: docs, windows: windows)) |