bugfix: unsubscribe from timelines on deck deletion

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-17 21:25:09 -04:00
parent d4082eb818
commit 1c547bbcaa
2 changed files with 43 additions and 3 deletions

View File

@@ -265,10 +265,25 @@ impl Decks {
}
}
pub fn remove_deck(&mut self, index: usize) {
pub fn remove_deck(
&mut self,
index: usize,
timeline_cache: &mut TimelineCache,
ndb: &mut nostrdb::Ndb,
pool: &mut enostr::RelayPool,
) {
let Some(deck) = self.remove_deck_internal(index) else {
return;
};
delete_deck(deck, timeline_cache, ndb, pool);
}
fn remove_deck_internal(&mut self, index: usize) -> Option<Deck> {
let mut res = None;
if index < self.decks.len() {
if self.decks.len() > 1 {
self.decks.remove(index);
res = Some(self.decks.remove(index));
let info_prefix = format!("Removed deck at index {index}");
match index.cmp(&self.active_deck) {
@@ -311,6 +326,26 @@ impl Decks {
} else {
error!("index was out of bounds");
}
res
}
}
fn delete_deck(
mut deck: Deck,
timeline_cache: &mut TimelineCache,
ndb: &mut nostrdb::Ndb,
pool: &mut enostr::RelayPool,
) {
let cols = deck.columns_mut();
let num_cols = cols.num_columns();
for i in (0..num_cols).rev() {
let kinds_to_pop = cols.delete_column(i);
for kind in &kinds_to_pop {
if let Err(err) = timeline_cache.pop(kind, ndb, pool) {
error!("error popping timeline: {err}");
}
}
}
}

View File

@@ -119,7 +119,12 @@ impl SwitchingAction {
get_decks_mut(ctx.accounts, decks_cache).set_active(index)
}
DecksAction::Removing(index) => {
get_decks_mut(ctx.accounts, decks_cache).remove_deck(index)
get_decks_mut(ctx.accounts, decks_cache).remove_deck(
index,
timeline_cache,
ctx.ndb,
ctx.pool,
);
}
},
}