From fc79faa46832173a5bec2303684cd4b73b515610 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 1 May 2026 19:25:14 +0000 Subject: [PATCH] fix(nests): clear NestBridge on logout and account switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../amethyst/ui/screen/AccountSessionManager.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt index ee43b4c4d..c26f6840d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt @@ -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())