bugfix: unsubscribe all decks when log out account

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-17 21:31:10 -04:00
parent 1c547bbcaa
commit 0b27282985
2 changed files with 38 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
use std::collections::{hash_map::ValuesMut, HashMap}; use std::collections::{hash_map::ValuesMut, HashMap};
use enostr::Pubkey; use enostr::{Pubkey, RelayPool};
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::{AppContext, FALLBACK_PUBKEY}; use notedeck::{AppContext, FALLBACK_PUBKEY};
use tracing::{error, info}; use tracing::{error, info};
@@ -155,9 +155,24 @@ impl DecksCache {
} }
} }
pub fn remove_for(&mut self, key: &Pubkey) { pub fn remove(
&mut self,
key: &Pubkey,
timeline_cache: &mut TimelineCache,
ndb: &mut nostrdb::Ndb,
pool: &mut RelayPool,
) {
let Some(decks) = self.account_to_decks.remove(key) else {
return;
};
info!("Removing decks for {:?}", key); info!("Removing decks for {:?}", key);
self.account_to_decks.remove(key);
decks.unsubscribe_all(timeline_cache, ndb, pool);
if !self.account_to_decks.contains_key(&self.fallback_pubkey) {
self.account_to_decks
.insert(self.fallback_pubkey, Decks::default());
}
} }
pub fn get_fallback_pubkey(&self) -> &Pubkey { pub fn get_fallback_pubkey(&self) -> &Pubkey {
@@ -328,6 +343,17 @@ impl Decks {
} }
res res
} }
pub fn unsubscribe_all(
self,
timeline_cache: &mut TimelineCache,
ndb: &mut nostrdb::Ndb,
pool: &mut enostr::RelayPool,
) {
for deck in self.decks {
delete_deck(deck, timeline_cache, ndb, pool);
}
}
} }
fn delete_deck( fn delete_deck(

View File

@@ -94,9 +94,15 @@ impl SwitchingAction {
.router_mut() .router_mut()
.go_back(); .go_back();
} }
AccountsAction::Remove(to_remove) => { AccountsAction::Remove(to_remove) => 's: {
ctx.accounts if !ctx
.remove_account(to_remove, ctx.ndb, ctx.pool, ui_ctx); .accounts
.remove_account(to_remove, ctx.ndb, ctx.pool, ui_ctx)
{
break 's;
}
decks_cache.remove(to_remove, timeline_cache, ctx.ndb, ctx.pool);
} }
}, },
SwitchingAction::Columns(columns_action) => match *columns_action { SwitchingAction::Columns(columns_action) => match *columns_action {