From 731a40746650de8f87fb710ab471a6ab85eb90d3 Mon Sep 17 00:00:00 2001 From: mikupls <93015331+mikupls@users.noreply.github.com> Date: Fri, 19 Nov 2021 06:42:53 +0100 Subject: [PATCH] Collapse (sticky) bot comments by default. (#321) * Collapse bot comments by default. Comments are considered bot comments if they are posted by a moderator and are stickied. Some false positives are expected. * Remove unneeded String conversion Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com> --- src/post.rs | 9 +++++++++ src/utils.rs | 1 + templates/comment.html | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/post.rs b/src/post.rs index cf34162..bde5c5b 100644 --- a/src/post.rs +++ b/src/post.rs @@ -184,6 +184,14 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, let id = val(&comment, "id"); let highlighted = id == highlighted_comment; + // Many subreddits have a default comment posted about the sub's rules etc. + // Many libreddit users do not wish to see this kind of comment by default. + // Reddit does not tell us which users are "bots", so a good heuristic is to + // collapse stickied moderator comments. + let is_moderator_comment = data["distinguished"].as_str().unwrap_or_default() == "moderator"; + let is_stickied = data["stickied"].as_bool().unwrap_or_default(); + let collapsed = is_moderator_comment && is_stickied; + Comment { id, kind, @@ -216,6 +224,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, edited, replies, highlighted, + collapsed, } }) .collect() diff --git a/src/utils.rs b/src/utils.rs index 380b976..1e0125a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -334,6 +334,7 @@ pub struct Comment { pub edited: (String, String), pub replies: Vec, pub highlighted: bool, + pub collapsed: bool, } #[derive(Template)] diff --git a/templates/comment.html b/templates/comment.html index 10d77fe..e258520 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -8,7 +8,7 @@

{{ score.0 }}

-
+
{% if author.flair.flair_parts.len() > 0 %}