From dc5ff9d809ce00100e4726970d7368cf530dc28f Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 27 Apr 2018 11:21:32 +0300 Subject: [PATCH] h-gtk: Take into account the ignored_shows when detemening if podcast table is empty. If you've had one show and pressed unsub, instead of going to an empty view, it would stay to populated since it the db records where still there. --- hammond-data/src/dbqueries.rs | 4 ++-- hammond-gtk/src/stacks/content.rs | 5 ++--- hammond-gtk/src/stacks/show.rs | 5 ++++- hammond-gtk/src/widgets/show.rs | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index efd269c..ca9b44c 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -363,13 +363,13 @@ pub fn is_episodes_populated() -> Result { /// Check if the `podcast` table contains any rows /// /// Return true if `podcast table is populated. -pub fn is_podcasts_populated() -> Result { +pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result { use schema::podcast::dsl::*; let db = connection(); let con = db.get()?; - select(exists(podcast.as_query())) + select(exists(podcast.filter(id.ne_all(filter_ids)))) .get_result(&con) .map_err(From::from) } diff --git a/hammond-gtk/src/stacks/content.rs b/hammond-gtk/src/stacks/content.rs index a6af0b6..3bff486 100644 --- a/hammond-gtk/src/stacks/content.rs +++ b/hammond-gtk/src/stacks/content.rs @@ -63,9 +63,8 @@ impl Content { } pub fn update_shows_view(&self) { - let pop = self.shows.borrow().populated(); - pop.borrow_mut() - .update_shows() + self.shows.borrow_mut() + .update() .map_err(|err| error!("Failed to update ShowsView: {}", err)) .ok(); } diff --git a/hammond-gtk/src/stacks/show.rs b/hammond-gtk/src/stacks/show.rs index 89df1f0..c92dac0 100644 --- a/hammond-gtk/src/stacks/show.rs +++ b/hammond-gtk/src/stacks/show.rs @@ -6,6 +6,7 @@ use hammond_data::dbqueries::is_podcasts_populated; use app::Action; use stacks::PopulatedStack; +use utils::get_ignored_shows; use widgets::EmptyView; use std::cell::RefCell; @@ -82,7 +83,9 @@ impl ShowStack { fn determine_state(&mut self) -> Result<(), Error> { use self::ShowState::*; - if is_podcasts_populated()? { + let ign = get_ignored_shows()?; + debug!("IGNORED SHOWS {:?}", ign); + if is_podcasts_populated(&ign)? { self.switch_visible(Populated); } else { self.switch_visible(Empty); diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index 5ce4206..e4b7bd3 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -303,18 +303,20 @@ pub fn remove_show_notif(pd: Arc, sender: Sender) -> InAppNotif .map_err(|_| error!("Could not insert {} to the ignore list.", pd.title())) .ok(); - let callback = clone!(pd => move || { + let callback = clone!(pd, sender => move || { utils::uningore_show(pd.id()) .map_err(|err| error!("Error: {}", err)) .map_err(|_| error!("Could not remove {} from the ignore list.", pd.title())) .ok(); // Spawn a thread so it won't block the ui. - rayon::spawn(clone!(pd => move || { + rayon::spawn(clone!(pd, sender => move || { delete_show(&pd) .map_err(|err| error!("Error: {}", err)) .map_err(|_| error!("Failed to delete {}", pd.title())) .ok(); + + sender.send(Action::RefreshEpisodesView).ok(); })); glib::Continue(false) });