diff --git a/src/duplicates.rs b/src/duplicates.rs index 6a64fc8..98e37b2 100644 --- a/src/duplicates.rs +++ b/src/duplicates.rs @@ -193,7 +193,7 @@ pub async fn item(req: Request) -> Result, String> { params: DuplicatesParams { before, after, sort }, post, duplicates, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, num_posts_filtered, all_posts_filtered, diff --git a/src/post.rs b/src/post.rs index e467fe7..79b7648 100644 --- a/src/post.rs +++ b/src/post.rs @@ -55,7 +55,7 @@ pub async fn item(req: Request) -> Result, String> { Ok(response) => { // Parse the JSON into Post and Comment structs let post = parse_post(&response[0]["data"]["children"][0]).await; - let comments = parse_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req)); + let comments = parse_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &req); let url = req.uri().to_string(); // Use the Post and Comment structs to generate a website to show users @@ -63,7 +63,7 @@ pub async fn item(req: Request) -> Result, String> { comments, post, sort, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), single_thread, url, }) @@ -81,7 +81,7 @@ pub async fn item(req: Request) -> Result, String> { } // COMMENTS -fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, highlighted_comment: &str, filters: &HashSet) -> Vec { +fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, highlighted_comment: &str, filters: &HashSet, req: &Request) -> Vec { // Parse the comment JSON into a Vector of Comments let comments = json["data"]["children"].as_array().map_or(Vec::new(), std::borrow::ToOwned::to_owned); @@ -101,7 +101,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, // If this comment contains replies, handle those too let replies: Vec = if data["replies"].is_object() { - parse_comments(&data["replies"], post_link, post_author, highlighted_comment, filters) + parse_comments(&data["replies"], post_link, post_author, highlighted_comment, filters, req) } else { Vec::new() }; @@ -169,6 +169,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, awards, collapsed, is_filtered, + prefs: Preferences::new(req), } }) .collect() diff --git a/src/search.rs b/src/search.rs index 87965c3..1322e39 100644 --- a/src/search.rs +++ b/src/search.rs @@ -105,7 +105,7 @@ pub async fn find(req: Request) -> Result, String> { restrict_sr: param(&path, "restrict_sr").unwrap_or_default(), typed, }, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, is_filtered: true, all_posts_filtered: false, @@ -131,7 +131,7 @@ pub async fn find(req: Request) -> Result, String> { restrict_sr: param(&path, "restrict_sr").unwrap_or_default(), typed, }, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, is_filtered: false, all_posts_filtered, diff --git a/src/settings.rs b/src/settings.rs index 0fd2640..4aa0a09 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,7 +19,7 @@ struct SettingsTemplate { // CONSTANTS -const PREFS: [&str; 11] = [ +const PREFS: [&str; 12] = [ "theme", "front_page", "layout", @@ -31,6 +31,7 @@ const PREFS: [&str; 11] = [ "use_hls", "hide_hls_notification", "autoplay_videos", + "hide_awards", ]; // FUNCTIONS @@ -39,7 +40,7 @@ const PREFS: [&str; 11] = [ pub async fn get(req: Request) -> Result, String> { let url = req.uri().to_string(); template(SettingsTemplate { - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, }) } diff --git a/src/subreddit.rs b/src/subreddit.rs index ef511c2..ae9851a 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -109,7 +109,7 @@ pub async fn community(req: Request) -> Result, String> { posts: Vec::new(), sort: (sort, param(&path, "t").unwrap_or_default()), ends: (param(&path, "after").unwrap_or_default(), "".to_string()), - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, redirect_url, is_filtered: true, @@ -128,7 +128,7 @@ pub async fn community(req: Request) -> Result, String> { posts, sort: (sort, param(&path, "t").unwrap_or_default()), ends: (param(&path, "after").unwrap_or_default(), after), - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, redirect_url, is_filtered: false, @@ -153,7 +153,7 @@ pub fn quarantine(req: Request, sub: String) -> Result, Str msg: "Please click the button below to continue to this subreddit.".to_string(), url: req.uri().to_string(), sub, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), }; Ok( @@ -200,7 +200,7 @@ pub async fn subscriptions_filters(req: Request) -> Result, let query = req.uri().query().unwrap_or_default().to_string(); - let preferences = Preferences::new(req); + let preferences = Preferences::new(&req); let mut sub_list = preferences.subscriptions; let mut filters = preferences.filters; @@ -313,7 +313,7 @@ pub async fn wiki(req: Request) -> Result, String> { sub, wiki: rewrite_urls(response["data"]["content_html"].as_str().unwrap_or("

Wiki not found

")), page, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, }), Err(msg) => { @@ -351,7 +351,7 @@ pub async fn sidebar(req: Request) -> Result, String> { // ), sub, page: "Sidebar".to_string(), - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, }), Err(msg) => { diff --git a/src/user.rs b/src/user.rs index 6c991ef..3813728 100644 --- a/src/user.rs +++ b/src/user.rs @@ -56,7 +56,7 @@ pub async fn profile(req: Request) -> Result, String> { sort: (sort, param(&path, "t").unwrap_or_default()), ends: (param(&path, "after").unwrap_or_default(), "".to_string()), listing, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, redirect_url, is_filtered: true, @@ -77,7 +77,7 @@ pub async fn profile(req: Request) -> Result, String> { sort: (sort, param(&path, "t").unwrap_or_default()), ends: (param(&path, "after").unwrap_or_default(), after), listing, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, redirect_url, is_filtered: false, diff --git a/src/utils.rs b/src/utils.rs index 06237e9..8badd6e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -357,6 +357,7 @@ pub struct Comment { pub awards: Awards, pub collapsed: bool, pub is_filtered: bool, + pub prefs: Preferences, } #[derive(Default, Clone)] @@ -472,6 +473,7 @@ pub struct Preferences { pub post_sort: String, pub subscriptions: Vec, pub filters: Vec, + pub hide_awards: String, } #[derive(RustEmbed)] @@ -481,7 +483,7 @@ pub struct ThemeAssets; impl Preferences { // Build preferences from cookies - pub fn new(req: Request) -> Self { + pub fn new(req: &Request) -> Self { // Read available theme names from embedded css files. // Always make the default "system" theme available. let mut themes = vec!["system".to_string()]; @@ -504,6 +506,7 @@ impl Preferences { post_sort: setting(&req, "post_sort"), subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), filters: setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + hide_awards: setting(&req, "hide_awards"), } } } @@ -820,7 +823,7 @@ pub async fn error(req: Request, msg: impl ToString) -> Result{{ rel_time }} {% if edited.0 != "".to_string() %}edited {{ edited.0 }}{% endif %} - {% if !awards.is_empty() %} + {% if !awards.is_empty() && prefs.hide_awards != "on" %} {% for award in awards.clone() %} diff --git a/templates/duplicates.html b/templates/duplicates.html index db6afc7..4344325 100644 --- a/templates/duplicates.html +++ b/templates/duplicates.html @@ -65,7 +65,7 @@ {{ post.rel_time }} - {% if !post.awards.is_empty() %} + {% if !post.awards.is_empty() && prefs.hide_awards != "on" %} {% for award in post.awards.clone() %} {{ award.name }} @@ -104,4 +104,4 @@ {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/settings.html b/templates/settings.html index b4bab8c..1df8c1f 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -83,6 +83,11 @@ +
+ + + +
diff --git a/templates/utils.html b/templates/utils.html index 639b0d8..a1095d2 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -73,7 +73,7 @@ {% endif %} {{ post.rel_time }} - {% if !post.awards.is_empty() %} + {% if !post.awards.is_empty() && prefs.hide_awards != "on" %} {% for award in post.awards.clone() %} @@ -178,7 +178,7 @@ {{ post.rel_time }} - {% if !post.awards.is_empty() %} + {% if !post.awards.is_empty() && prefs.hide_awards != "on" %} {% for award in post.awards.clone() %} {{ award.name }}