mirror of
https://github.com/redlib-org/redlib.git
synced 2025-05-15 14:32:50 +00:00
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>
This commit is contained in:
parent
34ea679519
commit
731a407466
3 changed files with 11 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -334,6 +334,7 @@ pub struct Comment {
|
|||
pub edited: (String, String),
|
||||
pub replies: Vec<Comment>,
|
||||
pub highlighted: bool,
|
||||
pub collapsed: bool,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue