0
2
iOS: Settings lists the accounts kept, switching between them as the web does
Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.
ios/Grain/Config.swift+6−0
| @@ -66,6 +66,10 @@ struct GrainConfig: Sendable { | ||
/// whether it offers a new account, and who matches a typed handle; | ||
/// nil where the file has no `signIn`. | ||
let signIn: SignInPlan? | ||
/// What a row of the accounts shows, as the web shell's (`frame.account.picture`): | ||
/// the call each account's own profile is read with, and the paths of its | ||
/// picture, name and handle in the answer (in a query's `response`). | ||
let accountPicture: (call: Call, at: String?, name: String?, handle: String?)? | ||
| ||
/// The one bundled with the app. | ||
static let bundled: GrainConfig = { | ||
| @@ -94,6 +98,8 @@ struct GrainConfig: Sendable { | ||
routes = Route.all(in: json) | ||
push = PushPlan(json["push"]) | ||
signIn = SignInPlan(app: json) | ||
let picture = json["frame"]?["account"]?["picture"] | ||
accountPicture = Self.call(picture?["call"]).map { ($0, picture?.str("at"), picture?.str("name"), picture?.str("handle")) } | ||
} | ||
| ||
/// A `{name, args}`. | ||
ios/Grain/GrainApp.swift+2−0
| @@ -50,6 +50,8 @@ struct ShellView: View { | ||
.tag(i) | ||
} | ||
} | ||
// Every tab drawn anew as the tabs start afresh (another account), as the web loads its page anew. | ||
.id(shell.starts) | ||
.tint(shell.config.color(.primary)) | ||
.environment(\.hudTheme, shell.config.theme(shell.preferredScheme ?? scheme)) | ||
.preferredColorScheme(shell.preferredScheme) | ||
ios/Grain/LevelScreen.swift+8−3
| @@ -83,6 +83,8 @@ struct LevelScreen: View { | ||
} | ||
// A tab's call slow to come: the page list a skeleton, the rest as it is. | ||
.onChange(of: level.slow && level.swapping, initial: true) { _, slow in context.pending = slow } | ||
// An account's row read (its name, its picture): Settings' Accounts draws it. | ||
.onChange(of: shell.accounts) { context.accounts = level.viewer == nil ? nil : shell.hostAccounts } | ||
.onDisappear { Task { await shell.feedback.flush() } } | ||
} | ||
| ||
| @@ -158,9 +160,10 @@ extension ViewContext { | ||
/// result made as none draws no actions, no forms and no Sign out; each | ||
/// done (an action, a tool that writes) is told (`wrote`); a | ||
/// notification procedure called (as updateSeen) asks the unread count | ||
/// afresh. A view's Sign out (`{host: signOut}`) signs the shell out; | ||
/// signed out, a form's Sign in to comment (a Compose's `signIn`) asks | ||
/// the shell to sign in. | ||
/// afresh. A view's Sign out (`{host: signOut}`) signs the shell out, | ||
/// and its `Accounts` lists the accounts kept on the device, switching | ||
/// and adding through the shell; signed out, a form's Sign in to comment | ||
/// (a Compose's `signIn`) asks the shell to sign in. | ||
@MainActor | ||
func wire( | ||
level: Level, | ||
| @@ -196,8 +199,10 @@ extension ViewContext { | ||
onUpload = nil | ||
onHost = nil | ||
onSignIn = { shell.askSignIn() } | ||
accounts = nil | ||
} else { | ||
onSignIn = nil | ||
accounts = shell.hostAccounts | ||
onHost = { what in | ||
switch what { | ||
case .signOut: Task { await shell.signOut() } | ||
ios/Grain/Shell.swift+115−11
| @@ -4,10 +4,10 @@ import SwiftUI | ||
import UserNotifications | ||
| ||
/// The app's state, as the web shell's (next/src/App.svelte): the server it | ||
/// calls, the account signed in to it, if any, the tab chosen, and each | ||
/// tab's navigation stack: its root, the tab's call (its guest call signed | ||
/// out), and the levels opened over it. Signing in or out starts every tab | ||
/// afresh. | ||
/// calls, the accounts kept on the device and the one in use, if any, the | ||
/// tab chosen, and each tab's navigation stack: its root, the tab's call | ||
/// (its guest call signed out), and the levels opened over it. Signing in | ||
/// or out, or switching accounts, starts every tab afresh. | ||
@MainActor @Observable | ||
final class Shell { | ||
let config = GrainConfig.bundled | ||
| @@ -60,6 +60,18 @@ final class Shell { | ||
private(set) var signingIn = false | ||
/// Why the last sign-in did not happen. | ||
var signInError: String? | ||
/// The accounts kept on the device, as Settings' Accounts lists them: in | ||
/// the order they were first kept here (not reordered by use, as the | ||
/// web's), each with its picture, name and handle as its own profile | ||
/// answered (`rows`), else the handle it was kept with. | ||
private(set) var accounts: [HostAccount] = [] | ||
/// Each account's row as its own profile answered it, read with its own | ||
/// tokens, by DID, and until when it is drawn without being read again. | ||
@ObservationIgnored private var rows: [String: (row: HostAccount, until: Date)] = [:] | ||
/// How many times every tab started afresh (`start`): the tabs are drawn | ||
/// anew each time, as the web loads its page anew, so no screen keeps | ||
/// what it held as the account before (an open form, where it scrolled). | ||
private(set) var starts = 0 | ||
@ObservationIgnored private(set) var feedback: Interactions! | ||
| ||
/// The preview of the next grain.social, a HUD server on grain's host. | ||
| @@ -90,11 +102,12 @@ final class Shell { | ||
| ||
/// Every tab from its root, as the account (or no one) sees it, no | ||
/// screen's last tree kept from before (`LastTree`, one account's | ||
/// alone), a tab with `first` from the root the account's data chooses | ||
/// (`chosenRoot`: Home, the first feed pinned), which its root level | ||
/// waits for before it draws; signed in, the device registered for push | ||
/// as the account, as grain-ios does once someone is signed in (asking | ||
/// leave to notify the first time). | ||
/// alone) and every screen drawn anew (`starts`), a tab with `first` | ||
/// from the root the account's data chooses (`chosenRoot`: Home, the | ||
/// first feed pinned), which its root level waits for before it draws; | ||
/// the accounts kept listed afresh; signed in, the device registered for | ||
/// push as the account, as grain-ios does once someone is signed in | ||
/// (asking leave to notify the first time). | ||
private func start() { | ||
LastTree.clear() | ||
pending = [:] | ||
| @@ -116,6 +129,10 @@ final class Shell { | ||
paths = config.tabs.map { _ in [] } | ||
stories = nil | ||
sheet = nil | ||
page = nil | ||
starts += 1 | ||
listAccounts() | ||
readAccounts() | ||
unread = 0 | ||
preferredScheme = nil | ||
Task { await refreshUnread() } | ||
| @@ -393,15 +410,102 @@ final class Shell { | ||
} | ||
| ||
/// What a session tells when it ends, signing out or by a refused | ||
/// renewal: the app goes on as another account kept, else signed out. | ||
/// renewal: the app goes on as the account used before it, else signed | ||
/// out. Another account's (its row read with its own tokens) leaves the | ||
/// accounts listed. | ||
private var ended: AccountSession.Ended { | ||
{ [weak self] gone in | ||
guard let self, self.session === gone else { return } | ||
guard let self else { return } | ||
guard self.session === gone else { return self.listAccounts() } | ||
self.session = AccountSession.restore(self.serverURL, ended: self.ended) | ||
self.start() | ||
} | ||
} | ||
| ||
/// The accounts as Settings' `Accounts` draws them, switching and adding | ||
/// through the shell; nil signed out. | ||
var hostAccounts: HostAccounts? { | ||
guard let session else { return nil } | ||
return HostAccounts( | ||
list: accounts, current: session.did, | ||
use: { did in Task { await self.use(did) } }, | ||
add: { self.askSignIn() } | ||
) | ||
} | ||
| ||
/// Go on as another account kept on the device, `did`, as the web loads | ||
/// its page anew: what feeds were told goes first as the account in use, | ||
/// and the device's push token is unregistered as it; then every tab | ||
/// starts afresh as `did` (`start`), registered for push as it, nothing | ||
/// of the account before drawn again. | ||
func use(_ did: String) async { | ||
guard let before = session, did != before.did else { return } | ||
await feedback.flush() | ||
guard session === before else { return } | ||
guard let found = AccountSession.restore(serverURL, did: did, ended: ended) else { return listAccounts() } | ||
await push?.signingOut() | ||
session = found | ||
start() | ||
} | ||
| ||
/// Where the order the accounts were first kept in is kept, by the | ||
/// server's origin, as the accounts are: DIDs, no secret. | ||
private var orderKey: String { "accounts.order " + (AuthServer.origin(of: serverURL) ?? serverURL.absoluteString) } | ||
/// How long an account's row is drawn without being read again, as the web's. | ||
private static let rowLife: TimeInterval = 600 | ||
| ||
/// The accounts kept, listed afresh in the order they were first kept | ||
/// (those kept before the order was, the one used longest ago first), | ||
/// each its row as read, else its handle as kept; rows of those no | ||
/// longer kept let go. | ||
private func listAccounts() { | ||
let kept = AccountSession.kept(serverURL) | ||
let dids = Set(kept.map(\.did)) | ||
var order = UserDefaults.standard.stringArray(forKey: orderKey) ?? [] | ||
order.removeAll { !dids.contains($0) } | ||
order += kept.reversed().map(\.did).filter { !order.contains($0) } | ||
UserDefaults.standard.set(order, forKey: orderKey) | ||
rows = rows.filter { dids.contains($0.key) } | ||
let handles = Dictionary(kept.map { ($0.did, $0.handle) }, uniquingKeysWith: { first, _ in first }) | ||
accounts = order.map { did in rows[did]?.row ?? HostAccount(did: did, handle: handles[did] ?? nil) } | ||
} | ||
| ||
/// Read each account's row, as the app file's `frame.account.picture` | ||
/// says, with its own tokens: the one in use's each time the tabs | ||
/// start, another's once its row is older than `rowLife`. One whose | ||
/// read fails keeps the row it had. | ||
private func readAccounts() { | ||
guard let plan = config.accountPicture, let current = session else { return } | ||
for account in accounts where account.did == current.did || (rows[account.did]?.until ?? .distantPast) < .now { | ||
let reader = account.did == current.did ? current : AccountSession.restore(serverURL, did: account.did, inUse: false, ended: ended) | ||
guard let reader else { continue } | ||
let fallback = account.handle | ||
Task { | ||
let client = HUDClient(base: serverURL, session: reader) | ||
guard let result = try? await client.call(plan.call), !result.isError else { return } | ||
// Signed out of meanwhile: no row kept for it. | ||
guard let at = accounts.firstIndex(where: { $0.did == account.did }) else { return } | ||
let row = Self.row(of: account.did, result.structuredContent, plan, handle: fallback) | ||
rows[account.did] = (row, Date.now.addingTimeInterval(Self.rowLife)) | ||
accounts[at] = row | ||
} | ||
} | ||
} | ||
| ||
/// An account's row from its own profile's answer: its picture (an https | ||
/// URL), name and handle where the plan's paths find them, else the | ||
/// handle it was kept with. | ||
nonisolated static func row(of did: String, _ answer: JSON?, _ plan: (call: Call, at: String?, name: String?, handle: String?), handle kept: String?) -> HostAccount { | ||
let data = answer?["response"] ?? answer | ||
func text(_ path: String?) -> String? { | ||
guard let path else { return nil } | ||
let found = path.split(separator: ".").reduce(data) { $0?[String($1)] } | ||
return found?.string.flatMap { $0.isEmpty ? nil : $0 } | ||
} | ||
let picture = text(plan.at).flatMap { $0.hasPrefix("https://") ? $0 : nil } | ||
return HostAccount(did: did, handle: text(plan.handle) ?? kept, name: text(plan.name), picture: picture) | ||
} | ||
| ||
/// Sign in to the server as `handle` (or a DID), in the system's browser | ||
/// sheet, the handle sent as the request's `login_hint`, as the HUD app | ||
/// does; or, with `create`, as a new account made at the server's | ||
ios/README.md+4−3
| @@ -9,7 +9,7 @@ its tool calls made on a HUD server's `/mcp`. Its tabs and look come from | ||
guest; Sign in goes through the server's OAuth. | ||
| ||
- `Grain/GrainApp.swift`: the app, its tab bar and each tab's stack; its app delegate, HUDKit's `PushAppDelegate`; grain.social links opened as their routes. | ||
- `Grain/Shell.swift`: the server, the account, each tab's levels, signing in and out, push, and opening a route's path. A level opened again draws its tree as last drawn at once (HUDKit's `LastTree`: the account's own, at most 10 minutes old) while its call is read afresh; signing in or out lets them all go, and a write the account's. | ||
- `Grain/Shell.swift`: the server, the accounts kept on the device and the one in use, each tab's levels, signing in and out, switching accounts, push, and opening a route's path. Settings' Accounts lists every account kept (in the order first kept, each its picture, name and handle as its own profile answered, read with its own tokens and kept 10 minutes, as `frame.account.picture` says), the one in use ticked; a tap on another switches to it, Add account signs in to one more (one kept already has its tokens replaced, no second row), and Sign out (or Delete account's) leaves the account used before it. Signing in, out or switching starts every tab afresh, as the web loads its page anew: no screen, last tree, read-ahead, badge or open form of the account before is drawn again. A level opened again draws its tree as last drawn at once (HUDKit's `LastTree`: the account's own, at most 10 minutes old) while its call is read afresh; a write lets the account's go. | ||
- `Grain/LevelScreen.swift`: one level, its view drawn by HUDKit's TreeView, and how a view's context is wired. Each time a level shows (opened, gone back to, its tab chosen again) it is read afresh, a thin line moving under the bar meanwhile, the answer drawn in place where it was scrolled, with the pages loaded past the first kept after it. | ||
- `Grain/StoryPager.swift`: people's stories over the tabs, from the stories strip (a `pages` list), swiped between as grain-ios does. | ||
- `Grain/Config.swift`: `grain.social.json` read, its palettes as HUDKit themes, its `signIn` as HUDKit's `SignInPlan`. | ||
| @@ -55,8 +55,9 @@ in), the app asks to send notifications the first time, and with leave | ||
registers the device's APNs token with grain-serve as them | ||
(`social.grain.notification.registerPush`, `serviceDid` | ||
`did:web:grain.social`, `platform` `ios`, `appId` the bundle id), through | ||
the HUD server's `call_procedure`. Before signing out, or another account | ||
signing in, it unregisters the token as them (`unregisterPush`). The calls | ||
the HUD server's `call_procedure`. Before signing out, switching to | ||
another account or another signing in, it unregisters the token as them | ||
(`unregisterPush`), and registers it as the account now in use. The calls | ||
are `next/grain.social.json`'s `push`, which HUD checks as it loads the app | ||
file and HUDKit's `Push` makes. A tapped notification opens the route | ||
its `push.open` maps grain-serve's payload to: a gallery's | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Data/SignIn.swift+17−4
| @@ -315,6 +315,12 @@ struct KeptAccounts: Codable, Equatable { | ||
return true | ||
} | ||
| ||
/// The account `did`'s entry, else the one in use; nil where it is not kept. | ||
func entry(_ did: String?) -> Entry? { | ||
guard let did else { return current } | ||
return entries.first { $0.did == did } | ||
} | ||
| ||
/// The account `did` let go, if what is kept of it is still `tokens` | ||
/// (not since signed in to afresh); the next one is then in use. | ||
mutating func remove(_ did: String, holding tokens: Tokens) { | ||
| @@ -405,11 +411,18 @@ public actor AccountSession { | ||
| ||
/// The session kept for the server at `url` of `did`, in use from now | ||
/// on, or without one of the account in use; nil where none is kept. | ||
public static func restore(_ url: URL, did: String? = nil, ended: @escaping Ended) -> AccountSession? { | ||
/// Not `inUse`, it is only called as (an account's own row read with its | ||
/// own tokens), the account in use left as it is. | ||
public static func restore(_ url: URL, did: String? = nil, inUse: Bool = true, ended: @escaping Ended) -> AccountSession? { | ||
guard let origin = AuthServer.origin(of: url) else { return nil } | ||
let entry = try? KeptAccounts.change(origin) { kept -> KeptAccounts.Entry? in | ||
if let did, !kept.use(did) { return nil } | ||
return kept.current | ||
let entry: KeptAccounts.Entry? | ||
if inUse { | ||
entry = try? KeptAccounts.change(origin) { kept -> KeptAccounts.Entry? in | ||
if let did, !kept.use(did) { return nil } | ||
return kept.current | ||
} | ||
} else { | ||
entry = KeptAccounts.read(origin).entry(did) | ||
} | ||
return entry.map { AccountSession($0, ended: ended) } | ||
} | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Tree/ResolvedAccounts.swift+2−1
| @@ -43,7 +43,8 @@ struct ResolvedAccounts: View { | ||
return self.row(row) | ||
.openable(open) | ||
.accessibilityElement(children: .combine) | ||
.accessibilityAddTraits(row.current ? .isSelected : []) | ||
// Another account's row switches to it, as Add account adds one: both buttons. | ||
.accessibilityAddTraits(row.current ? .isSelected : .isButton) | ||
.accessibilityValue(row.current ? "Current account" : "") | ||
.accessibilityHint(row.current ? "" : "Switches to this account") | ||
} | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/Tree/ResolvedCompose.swift+56−3
| @@ -161,9 +161,10 @@ struct Composing: Identifiable { | ||
} | ||
| ||
extension View { | ||
/// The form being written, in its sheet; sent, its draft cleared. | ||
func composeSheet(_ composing: Binding<Composing?>, _ view: ViewContext) -> some View { | ||
sheet(item: composing) { writing in | ||
/// The form being written, in its sheet; sent, its draft cleared; gone, | ||
/// sent or not, `closed` told. | ||
func composeSheet(_ composing: Binding<Composing?>, _ view: ViewContext, closed: (() -> Void)? = nil) -> some View { | ||
sheet(item: composing, onDismiss: closed) { writing in | ||
let fields = ComposeField.all(writing.p) | ||
ComposeSheet(p: writing.p, fields: fields, form: writing.form, view: view) { | ||
view.memory.set(ResolvedCompose.key(writing.p), ComposeForm(fields: fields)) | ||
| @@ -171,3 +172,55 @@ extension View { | ||
} | ||
} | ||
} | ||
| ||
extension Drawn { | ||
/// The `Compose` its screen was opened at (an `open` query's `compose`: | ||
/// the one marked `open`, never a Menu's row), as the web's `formOf`. | ||
var openedForm: JSON? { | ||
guard case .tree(let ui) = self, let root = ui["root"] else { return nil } | ||
return Self.form(in: root) | ||
} | ||
| ||
private static func form(in node: JSON) -> JSON? { | ||
switch node["c"]?.string { | ||
case "Compose": return node["p"]?["open"] == .bool(true) ? node["p"] : nil | ||
case "Menu": return nil | ||
default: return node["k"]?.array?.lazy.compactMap(form(in:)).first | ||
} | ||
} | ||
| ||
/// Whether its screen opens at a form by itself (one's own Your story | ||
/// with none): an app draws that form alone (`OpenedForm`), not the screen. | ||
public var opensAtForm: Bool { openedForm != nil } | ||
} | ||
| ||
/// The form a tree's screen was opened at, alone: no button and no screen, | ||
/// its sheet open at once over whatever the app shows, its writes and | ||
/// reload the context's, and `done` told as it closes, sent or not. As the | ||
/// web's Tree with `form`: a story pager whose page tapped opens at its | ||
/// form (Your story with none) draws this in place of the stories, and | ||
/// closes them once it is done, as a photo app's Your story goes to the | ||
/// camera and back. Where it has no form, or the app can't send it, it is | ||
/// done at once. | ||
public struct OpenedForm: View { | ||
let p: JSON? | ||
let context: ViewContext | ||
let done: @MainActor () -> Void | ||
@State private var composing: Composing? | ||
| ||
public init(drawn: Drawn, context: ViewContext, done: @escaping @MainActor () -> Void) { | ||
p = drawn.openedForm | ||
self.context = context | ||
self.done = done | ||
} | ||
| ||
public var body: some View { | ||
Color.clear | ||
.composeSheet($composing, context, closed: done) | ||
.environment(\.viewContext, context) | ||
.task { | ||
guard let p, ResolvedCompose.offered(p, ComposeField.all(p), context) else { return done() } | ||
composing = Composing(p, context) | ||
} | ||
} | ||
} | ||
vendor/hud/ios/HUDKit/Sources/HUDKit/View/Context.swift+14−3
| @@ -78,8 +78,9 @@ public struct HostAccounts { | ||
/// web renderer's view context: whether the view is trusted (an untrusted | ||
/// one's actions ask first), and where a click or an action goes. A handler | ||
/// left nil means the app does nothing of that kind: a link of it draws as | ||
/// text, an action draws nothing. Whether it is `active` is observed: a | ||
/// view drawn while it changes draws afresh. | ||
/// text, an action draws nothing. Whether it is `active`, `held` or | ||
/// `pending`, and its `accounts`, are observed: a view drawn while they | ||
/// change draws afresh. | ||
public final class ViewContext: @unchecked Sendable, Observable { | ||
public var trusted = false | ||
/// Whether the tree is the one in front: false for one drawn ahead of | ||
| @@ -161,7 +162,17 @@ public final class ViewContext: @unchecked Sendable, Observable { | ||
public var onSignIn: (@MainActor () -> Void)? | ||
/// The accounts the app is signed in to, for an `Accounts` node to | ||
/// switch between; with none (the app keeps none), it draws its children. | ||
public var accounts: HostAccounts? | ||
/// Observed, so rows the app reads later (a name, a picture) draw as they come. | ||
public var accounts: HostAccounts? { | ||
get { | ||
registrar.access(self, keyPath: \.accounts) | ||
return hostAccounts | ||
} | ||
set { | ||
registrar.withMutation(of: self, keyPath: \.accounts) { hostAccounts = newValue } | ||
} | ||
} | ||
private var hostAccounts: HostAccounts? | ||
/// An `Action` with `leave` has written: close the screen the tree is | ||
/// on, as after deleting the gallery it shows. With none, nothing more. | ||
public var onLeave: (@MainActor () -> Void)? | ||
vendor/hud/ios/HUDKit/Tests/HUDKitTests/HUDKitTests.swift+33−0
| @@ -426,6 +426,13 @@ private func conversation() throws -> (drawn: Drawn, root: JSON) { | ||
accounts.use(rows[0].did) | ||
accounts.add() | ||
#expect(asked == ["use did:plc:a", "add"]) | ||
// Rows the app reads later draw as they come: setting the accounts is observed. | ||
final class Changed: @unchecked Sendable { var yes = false } | ||
let changed = Changed() | ||
withObservationTracking { _ = view.accounts } onChange: { changed.yes = true } | ||
view.accounts = nil | ||
#expect(changed.yes) | ||
#expect(ResolvedAccounts.accounts(view) == nil) | ||
} | ||
| ||
/// A slide's children: its Menus at the end of its top row, the rest at | ||
| @@ -588,6 +595,22 @@ private func conversation() throws -> (drawn: Drawn, root: JSON) { | ||
let strip = [yours] + items | ||
#expect(ResolvedList.pages(strip, opened: 0) == Pages(calls: [mine, call("did:plc:a"), call("did:plc:b"), call("did:plc:c")], at: 0)) | ||
#expect(ResolvedList.pages(strip, opened: 1) == Pages(calls: [call("did:plc:a"), call("did:plc:b"), call("did:plc:c")], at: 0)) | ||
// With stories of one's own its call has no `compose`: a page as any other, the first. | ||
let withStories: JSON = ["open": ["call": ["name": "query", "args": ["method": "social.grain.story.getStories", "params": ["actor": "did:plc:me"]]]], "k": []] | ||
let own = Call("query", ["method": "social.grain.story.getStories", "params": ["actor": "did:plc:me"]]) | ||
#expect(ResolvedList.pages([withStories] + items, opened: 1) == Pages(calls: [own, call("did:plc:a"), call("did:plc:b"), call("did:plc:c")], at: 1)) | ||
} | ||
| ||
/// A screen opened at its form (the `Compose` marked `open`, not a | ||
/// Menu's row) opens at it; one with stories, or only a Menu's, doesn't. | ||
@Test func aScreenOpensAtTheFormMarkedOpen() { | ||
let compose = { (open: Bool) -> JSON in ["c": "Compose", "p": open ? ["label": "Add", "open": true] : ["label": "Add"]] } | ||
let tree = { (k: [JSON]) in Drawn.tree(["v": 1, "root": ["c": "Stack", "k": .array(k)]]) } | ||
#expect(tree([["c": "Slides", "k": [compose(true)]]]).opensAtForm) | ||
#expect(tree([["c": "Slides", "k": [compose(true)]]]).openedForm?["label"] == "Add") | ||
#expect(!tree([["c": "Slides", "k": [compose(false)]]]).opensAtForm) | ||
#expect(!tree([["c": "Menu", "k": [compose(true)]]]).opensAtForm) | ||
#expect(!Drawn.error("no").opensAtForm) | ||
} | ||
| ||
/// An action with `leave` closes its screen once it has written, one | ||
| @@ -945,6 +968,16 @@ private func conversation() throws -> (drawn: Drawn, root: JSON) { | ||
#expect(kept.listed.map(\.did) == ["did:plc:a", "did:plc:b"]) | ||
} | ||
| ||
@Test func anAccountsEntryIsFoundWithoutPuttingItInUse() { | ||
var kept = KeptAccounts() | ||
kept.keep(entry("did:plc:a", "a1")) | ||
kept.keep(entry("did:plc:b", "b1")) | ||
#expect(kept.entry("did:plc:a")?.tokens.access == "a1") | ||
#expect(kept.entry(nil)?.did == "did:plc:b") | ||
#expect(kept.entry("did:plc:z") == nil) | ||
#expect(kept.listed.map(\.did) == ["did:plc:b", "did:plc:a"]) | ||
} | ||
| ||
@Test func signingInAgainReplacesTheAccountKeepingItsHandle() { | ||
var kept = KeptAccounts() | ||
kept.keep(entry("did:plc:a", "a1", handle: "alice.test")) | ||