From 0d994172a0456c09a5265c3c9434c114f78f165b Mon Sep 17 00:00:00 2001 From: kernelkind Date: Mon, 7 Oct 2024 13:44:35 -0400 Subject: [PATCH] unsubscribe timeline on deletion Signed-off-by: kernelkind --- src/column.rs | 5 +++++ src/nav.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/column.rs b/src/column.rs index f826ab5b..62d45cdd 100644 --- a/src/column.rs +++ b/src/column.rs @@ -149,6 +149,11 @@ impl Columns { .1 } + pub fn find_timeline_for_column_index(&self, ind: usize) -> Option<&Timeline> { + let col_id = self.get_column_id_at_index(ind); + self.timelines.get(&col_id) + } + pub fn select_down(&mut self) { warn!("todo: implement select_down"); } diff --git a/src/nav.rs b/src/nav.rs index 7e1422e2..6af99458 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -18,6 +18,7 @@ use crate::{ use egui::{pos2, Color32, InnerResponse}; use egui_nav::{Nav, NavAction}; +use tracing::{error, info}; pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) { let col_id = app.columns.get_column_id_at_index(col); @@ -149,6 +150,20 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) { match title_response { TitleResponse::RemoveColumn => { app.columns_mut().request_deletion_at_index(col); + let tl = app.columns().find_timeline_for_column_index(col); + if let Some(timeline) = tl { + if let Some(sub_id) = timeline.subscription { + if let Err(e) = app.ndb.unsubscribe(sub_id) { + error!("unsubscribe error: {}", e); + } else { + info!( + "successfully unsubscribed from timeline {} with sub id {}", + timeline.id, + sub_id.id() + ); + } + } + } } } }