~ knotless Search/
↑↓ move↵ open⇧↵ all results

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

iOS: Settings lists the accounts kept, switching between them as the web does

Merged
Merged chadtmiller.com asked to merge into feature/hud from grain.social/grain:next/ios-accounts

What changes

Settings lists every account kept on the device. Each row shows the account's picture, name and @handle, and the one in use has a tick, as next.grain.social and grain-ios show them. Names and pictures come from each account's own profile (frame.account.picture in the app file), read with that account's own tokens and kept for 10 minutes, as the web shell does. The rows stay in the order the accounts were first kept: using one doesn't move it to the top. Until now, HUDKit's Accounts drew its children on iOS, so only the current account showed.

Tapping another account switches to it, as the web does with a fresh page load. Anything already reported to feeds is sent as the previous account first. Push is unregistered as that account and registered as the new one, then every tab starts again: LastTree is cleared, the stacks, stories, sheets and badge are reset, and the tab view is drawn anew (Shell.starts). No screen, open form or scroll position from the previous account stays.

Add account signs in to one more account. If the account is already kept, its tokens are replaced (HUDKit's KeptAccounts.keep) rather than a second row being added. Sign out, and the sign-out at the end of Delete account, remove only the account in use, and the app moves to the account used before it.

HUD 0e21d81 (vendored) makes three HUDKit changes. ViewContext.accounts is now observed, so rows read after the screen draws appear as they arrive. AccountSession.restore(inUse: false) gives a session for a kept account without making it the one in use, so another account's row can be read with its own tokens. VoiceOver treats another account's row as a button. The vendor also brings in ab46d11, which only changes HUDKit's ResolvedCompose.

Why

The iOS app already kept several accounts in the Keychain, and it already moved to another one when a session ended, but nothing let you see them or switch between them. The web (@hud/shell Sessions) and grain-ios both offer this.

How it was checked

  • just ios-test in HUD, including new tests for the observed accounts and for reading a kept account's entry without using it.
  • The iOS app on the simulator against HUD's harness: its reference PDS with the throwaway alice.test and bob.test, and a stand-in for Grain's AppView. It answers getProfile with "Alice (throwaway)" or "Bob (throwaway)" and a coloured avatar, and logs every call with the account that made it. An XCUITest (throwaway, not committed) went through the flow in one app session, with Settings opened from Profile's gear:
    1. Signed in as alice. Settings lists her alone, ticked.
    2. Add account → bob. Profile shows Bob.
    3. Settings lists both, with the tick on Bob.
    4. Tapped Alice. Settings closes, and Profile and Home redraw as Alice with nothing of Bob anywhere. Settings then ticks Alice.
    5. Add account → bob.test again. There are still two rows, now ticked on Bob.
    6. Sign out of Bob. Alice is left and in use, and Settings lists her alone.
  • In the stand-in's log, each switch and sign-out sent unregisterPush as the account leaving, then registerPush as the account in use. Every getProfile was made as the account it describes, including another account's row read while bob was in use (inUse: false).

Shortcomings

  • Delete account was not run end to end here. Its final step is the same {host: signOut} path as Sign out, which was checked.
  • Push was checked through the stand-in's log. No notification was sent to a device.
  • A refused token renewal for an account not in use drops that account's row, but this wasn't forced in the simulator.

Review

Start at Shell.use and Shell.listAccounts/readAccounts, and the .id(shell.starts) on the tab view.

pr-3-settings-both-bob.png

pr-4-profile-alice.png

pr-6-settings-alice-current.png

pr-9-settings-after-signout.png

Approved

This adds an Accounts list to Settings on iOS and lets you switch accounts from it. It reads each account's row with that account's own tokens, via the new restore(inUse: false), and keeps the rows 10 minutes. A switch flushes feedback, then unregisters push as the old account. It then restores the new account, restarts every tab, and .id(shell.starts) redraws the tab view. I read every changed file. Every symbol I checked exists (page, Push.signingOut, AccountSession.kept), and I didn't build it. The HUD vendor changes are covered by new tests.

I found nothing that must change. Two small things for you to check:

  • In use, restore(..., did:) marks the new account in use before push?.signingOut() runs. Unregistering still works, because Push keeps the old account's client. If the app dies between those two steps, the Keychain says the new account is in use while push is still registered as the old one. That window is short, and the next start() registers push as the account in use.
  • In readAccounts, each row-read Task writes rows and accounts after an await. If the accounts changed in the meantime, such as a sign-out of that account, the write can bring back a row for an account no longer kept until the next listAccounts. rows[account.did] = ... runs unconditionally, while accounts is only updated if the account is still listed. This is harmless for the display, but rows may keep a stale entry.

The vendor update goes through the repository's just vendor-hud path, as AGENTS.md asks.

Approved

Since my approval at 8d97bc5, the only change is in readAccounts. The Task now returns early if the account is no longer listed, so a signed-out account can't leave a stale rows entry. That answers the second point I raised last round. The first point, the short window in use, is unchanged and still harmless. I found nothing new.

Merged as 973b09d
Part of a stack of 2
  1. iOS: Settings lists the accounts kept, switching between them as the web does Landed as 973b09d
  2. main