From 30944579d7ceb8eaef5d4e94395df5c3032285ab Mon Sep 17 00:00:00 2001 From: nieve Date: Tue, 18 Jun 2024 00:21:00 -0400 Subject: [PATCH 1/4] add default filter config --- .env.example | 1 + app.json | 3 +++ src/config.rs | 12 ++++++++++++ src/instance_info.rs | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index b74e45c..d8d08ee 100644 --- a/.env.example +++ b/.env.example @@ -36,6 +36,7 @@ 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= +REDLIB_DEFAULT_FILTERS= # Hide awards by default REDLIB_DEFAULT_HIDE_AWARDS=off # Hide sidebar and summary 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..eea1ddf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -79,6 +79,10 @@ pub struct Config { #[serde(rename = "REDLIB_DEFAULT_SUBSCRIPTIONS")] #[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")] @@ -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(), From 1408c32a4dfd338978601dfe793a1f7aea48f411 Mon Sep 17 00:00:00 2001 From: nieve Date: Tue, 18 Jun 2024 00:25:29 -0400 Subject: [PATCH 2/4] Update .env.example --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index d8d08ee..5e187f9 100644 --- a/.env.example +++ b/.env.example @@ -36,6 +36,7 @@ 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 From 3491e754ac44bef07f3b9ad7c491918e4cb61556 Mon Sep 17 00:00:00 2001 From: nieve Date: Tue, 18 Jun 2024 00:30:53 -0400 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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/ From f460895cc04a1346fcafc0a4a8cb9bd879c1d01f Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Thu, 20 Jun 2024 07:56:43 -0400 Subject: [PATCH 4/4] chore(clippy): fix lint --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index eea1ddf..a787251 100644 --- a/src/config.rs +++ b/src/config.rs @@ -79,7 +79,7 @@ pub struct Config { #[serde(rename = "REDLIB_DEFAULT_SUBSCRIPTIONS")] #[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,