diff --git a/src/duplicates.rs b/src/duplicates.rs index d68d1b3..93f4df6 100644 --- a/src/duplicates.rs +++ b/src/duplicates.rs @@ -201,7 +201,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 1423e60..3031000 100644 --- a/src/post.rs +++ b/src/post.rs @@ -63,7 +63,7 @@ pub async fn item(req: Request) -> Result, String> { return Ok(nsfw_landing(req).await.unwrap_or_default()); } - 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 @@ -71,7 +71,7 @@ pub async fn item(req: Request) -> Result, String> { comments, post, sort, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), single_thread, url, }) @@ -89,7 +89,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); @@ -109,7 +109,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() }; @@ -177,6 +177,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 7158fdc..a8ac55f 100644 --- a/src/search.rs +++ b/src/search.rs @@ -110,7 +110,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, @@ -136,7 +136,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 af87d93..71692c4 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -115,7 +115,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, @@ -134,7 +134,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, @@ -159,7 +159,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( @@ -206,7 +206,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; @@ -319,7 +319,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) => { @@ -357,7 +357,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 3620fce..53f4090 100644 --- a/src/user.rs +++ b/src/user.rs @@ -65,7 +65,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, @@ -86,7 +86,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 8c8d273..daee4a9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -370,6 +370,7 @@ pub struct Comment { pub awards: Awards, pub collapsed: bool, pub is_filtered: bool, + pub prefs: Preferences, } #[derive(Default, Clone)] @@ -508,6 +509,7 @@ pub struct Preferences { pub post_sort: String, pub subscriptions: Vec, pub filters: Vec, + pub hide_awards: String, } #[derive(RustEmbed)] @@ -517,7 +519,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()]; @@ -540,6 +542,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"), } } } @@ -857,7 +860,7 @@ pub async fn error(req: Request, msg: impl ToString) -> Result) -> Result, String> let body = NSFWLandingTemplate { res, res_type, - prefs: Preferences::new(req), + prefs: Preferences::new(&req), url, } .render() diff --git a/templates/comment.html b/templates/comment.html index 61c44f5..d9b9c68 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -20,7 +20,7 @@ {% endif %} {{ 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 530176e..2f7eb9a 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -85,6 +85,11 @@ +
+ + + +
@@ -122,7 +127,7 @@

Note: settings and subscriptions are saved in browser cookies. Clearing your cookies will reset them.


-

You can restore your current settings and subscriptions after clearing your cookies using this link.

+

You can restore your current settings and subscriptions after clearing your cookies using this link.


{% if crate::utils::sfw_only() %}

This instance is SFW-only. It will block all NSFW content.

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 }}