Implement the shared HashSet with the ignored Shows ids
This commit is contained in:
@@ -17,8 +17,8 @@ use widgets::mark_all_watched;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Action {
|
||||
|
||||
@@ -15,8 +15,9 @@ use hammond_data::pipeline;
|
||||
use hammond_data::utils::checkup;
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::{Mutex, RwLock};
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread;
|
||||
|
||||
@@ -25,6 +26,28 @@ use app::Action;
|
||||
use chrono::Duration;
|
||||
use chrono::prelude::*;
|
||||
|
||||
lazy_static! {
|
||||
static ref IGNORESHOWS: Arc<Mutex<HashSet<i32>>> = Arc::new(Mutex::new(HashSet::new()));
|
||||
}
|
||||
|
||||
pub fn ignore_show(id: i32) -> Result<(), Error> {
|
||||
let mut guard = IGNORESHOWS.lock().map_err(|err| format_err!("{}", err))?;
|
||||
guard.insert(id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn uningore_show(id: i32) -> Result<(), Error> {
|
||||
let mut guard = IGNORESHOWS.lock().map_err(|err| format_err!("{}", err))?;
|
||||
guard.remove(&id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_ignored_shows() -> Result<Vec<i32>, Error> {
|
||||
let guard = IGNORESHOWS.lock().map_err(|err| format_err!("{}", err))?;
|
||||
let keys = guard.iter().cloned().collect::<Vec<_>>();
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
pub fn cleanup(cleanup_date: DateTime<Utc>) {
|
||||
if let Err(err) = checkup(cleanup_date) {
|
||||
error!("Check up failed: {}", err);
|
||||
|
||||
@@ -7,7 +7,7 @@ use hammond_data::EpisodeWidgetQuery;
|
||||
use hammond_data::dbqueries;
|
||||
|
||||
use app::Action;
|
||||
use utils::get_pixbuf_from_path;
|
||||
use utils::{get_ignored_shows, get_pixbuf_from_path};
|
||||
use widgets::EpisodeWidget;
|
||||
|
||||
use std::sync::mpsc::Sender;
|
||||
@@ -77,7 +77,8 @@ impl Default for EpisodesView {
|
||||
impl EpisodesView {
|
||||
pub fn new(sender: Sender<Action>) -> Result<EpisodesView, Error> {
|
||||
let view = EpisodesView::default();
|
||||
let episodes = dbqueries::get_episodes_widgets_filter_limit(&[], 50)?;
|
||||
let ignore = get_ignored_shows()?;
|
||||
let episodes = dbqueries::get_episodes_widgets_filter_limit(&ignore, 50)?;
|
||||
let now_utc = Utc::now();
|
||||
|
||||
episodes.into_iter().for_each(|ep| {
|
||||
|
||||
@@ -6,7 +6,7 @@ use hammond_data::Podcast;
|
||||
use hammond_data::dbqueries;
|
||||
|
||||
use app::Action;
|
||||
use utils::get_pixbuf_from_path;
|
||||
use utils::{get_ignored_shows, get_pixbuf_from_path};
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::Sender;
|
||||
@@ -54,7 +54,8 @@ impl ShowsPopulated {
|
||||
}
|
||||
|
||||
fn populate_flowbox(&self) -> Result<(), Error> {
|
||||
let podcasts = dbqueries::get_podcasts()?;
|
||||
let ignore = get_ignored_shows()?;
|
||||
let podcasts = dbqueries::get_podcasts_filter(&ignore)?;
|
||||
|
||||
podcasts.into_iter().map(Arc::new).for_each(|parent| {
|
||||
let flowbox_child = ShowsChild::new(parent);
|
||||
|
||||
@@ -7,7 +7,7 @@ use open;
|
||||
|
||||
use hammond_data::Podcast;
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::utils::{replace_extra_spaces};
|
||||
use hammond_data::utils::replace_extra_spaces;
|
||||
|
||||
use app::Action;
|
||||
use utils::get_pixbuf_from_path;
|
||||
|
||||
Reference in New Issue
Block a user