fix(nests): clear NestBridge on logout and account switch

NestBridge holds a process-singleton AccountViewModel reference so
NestActivity (separately tasked) can read the active account without
serialising a NostrSigner through an Intent extra. The bridge's doc
promised it'd be cleared on logout / account switch but no call site
existed — so the audio-room activity could pick up a stale
AccountViewModel from the previous session and sign with the old
key after an account swap.

Wire NestBridge.clear() into both transition points in
AccountSessionManager: switchUserSync (always) and logOff (only when
the current account is being torn down).

https://claude.ai/code/session_01DMeCvWyBYVVVPez2hwqCs4
This commit is contained in:
Claude
2026-05-01 19:25:14 +00:00
parent 714159f816
commit fc79faa468
@@ -331,6 +331,12 @@ class AccountSessionManager(
accountInfo: AccountInfo,
routeBuilder: ((account: Account) -> Route?)? = null,
) {
// The Nest audio-room activity reads the active AccountViewModel
// through a process-singleton bridge. Drop the previous user's
// ref before swapping so a stale ref can't survive into the new
// session — see [NestBridge].
com.vitorpamplona.amethyst.ui.screen.loggedIn.nests.room.activity.NestBridge
.clear()
localPreferences.switchToAccount(accountInfo)
loginWithDefaultAccount(routeBuilder)
}
@@ -351,6 +357,11 @@ class AccountSessionManager(
fun logOff(accountInfo: AccountInfo) {
scope.launch(Dispatchers.IO) {
if (accountInfo.npub == currentAccountNPub()) {
// Drop the Nest bridge ref before tearing down the
// current account so the audio-room activity can't
// pick up a stale AccountViewModel — see [NestBridge].
com.vitorpamplona.amethyst.ui.screen.loggedIn.nests.room.activity.NestBridge
.clear()
// log off and relogin with the 0 account
localPreferences.deleteAccount(accountInfo)
accountsCache.removeAccount(accountInfo.npub.bechToBytes().toHexKey())