diff --git a/.env.example b/.env.example index b74e45c..5e187f9 100644 --- a/.env.example +++ b/.env.example @@ -36,6 +36,8 @@ REDLIB_DEFAULT_HIDE_HLS_NOTIFICATION=off REDLIB_DEFAULT_AUTOPLAY_VIDEOS=off # Define a default list of subreddit subscriptions (format: sub1+sub2+sub3) REDLIB_DEFAULT_SUBSCRIPTIONS= +# Define a default list of subreddit filters (format: sub1+sub2+sub3) +REDLIB_DEFAULT_FILTERS= # Hide awards by default REDLIB_DEFAULT_HIDE_AWARDS=off # Hide sidebar and summary diff --git a/.gitignore b/.gitignore index a8d371a..6ca325c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /target .env +redlib.toml + # Idea Files .idea/ diff --git a/app.json b/app.json index e1ae650..b3e8616 100644 --- a/app.json +++ b/app.json @@ -59,6 +59,9 @@ "REDLIB_DEFAULT_SUBSCRIPTIONS": { "required": false }, + "REDLIB_DEFAULT_FILTERS": { + "required": false + }, "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION": { "required": false }, diff --git a/src/config.rs b/src/config.rs index e345537..a787251 100644 --- a/src/config.rs +++ b/src/config.rs @@ -80,6 +80,10 @@ pub struct Config { #[serde(alias = "LIBREDDIT_DEFAULT_SUBSCRIPTIONS")] pub(crate) default_subscriptions: Option, + #[serde(rename = "REDLIB_DEFAULT_FILTERS")] + #[serde(alias = "LIBREDDIT_DEFAULT_FILTERS")] + pub(crate) default_filters: Option, + #[serde(rename = "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")] #[serde(alias = "LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")] pub(crate) default_disable_visit_reddit_confirmation: Option, @@ -134,6 +138,7 @@ impl Config { default_hide_sidebar_and_summary: parse("REDLIB_DEFAULT_HIDE_SIDEBAR_AND_SUMMARY"), default_hide_score: parse("REDLIB_DEFAULT_HIDE_SCORE"), default_subscriptions: parse("REDLIB_DEFAULT_SUBSCRIPTIONS"), + default_filters: parse("REDLIB_DEFAULT_FILTERS"), default_disable_visit_reddit_confirmation: parse("REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"), banner: parse("REDLIB_BANNER"), robots_disable_indexing: parse("REDLIB_ROBOTS_DISABLE_INDEXING"), @@ -159,6 +164,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_DEFAULT_HIDE_SIDEBAR_AND_SUMMARY" => config.default_hide_sidebar_and_summary.clone(), "REDLIB_DEFAULT_HIDE_SCORE" => config.default_hide_score.clone(), "REDLIB_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(), + "REDLIB_DEFAULT_FILTERS" => config.default_filters.clone(), "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(), "REDLIB_BANNER" => config.banner.clone(), "REDLIB_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(), @@ -231,6 +237,12 @@ fn test_default_subscriptions() { assert_eq!(get_setting("REDLIB_DEFAULT_SUBSCRIPTIONS"), Some("news+bestof".into())); } +#[test] +#[sealed_test(env = [("REDLIB_DEFAULT_FILTERS", "news+bestof")])] +fn test_default_filters() { + assert_eq!(get_setting("REDLIB_DEFAULT_FILTERS"), Some("news+bestof".into())); +} + #[test] #[sealed_test] fn test_pushshift() { diff --git a/src/instance_info.rs b/src/instance_info.rs index 462e09c..85c4883 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -146,6 +146,7 @@ impl InstanceInfo { ["Use HLS", &convert(&self.config.default_use_hls)], ["Hide HLS notification", &convert(&self.config.default_hide_hls_notification)], ["Subscriptions", &convert(&self.config.default_subscriptions)], + ["Filters", &convert(&self.config.default_filters)], ]) .with_header_row(["Default preferences"]), ); @@ -177,7 +178,8 @@ impl InstanceInfo { Default blur NSFW: {:?}\n Default use HLS: {:?}\n Default hide HLS notification: {:?}\n - Default subscriptions: {:?}\n", + Default subscriptions: {:?}\n + Default filters: {:?}\n", self.package_name, self.crate_version, self.git_commit, @@ -200,6 +202,7 @@ impl InstanceInfo { self.config.default_use_hls, self.config.default_hide_hls_notification, self.config.default_subscriptions, + self.config.default_filters, ) } StringType::Html => self.to_table(),