Implement 'posts hidden because of NSFW'. (Resolves #159) (#619)

This commit is contained in:
Daniel Valentine 2022-11-07 20:54:49 -07:00 committed by GitHub
parent 5c366e14a3
commit 465d9b7ba7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 9 deletions

View file

@ -24,6 +24,8 @@ struct SubredditTemplate {
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
/// and all fetched posts being filtered).
all_posts_filtered: bool,
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
all_posts_hidden_nsfw: bool,
}
#[derive(Template)]
@ -111,12 +113,13 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
redirect_url,
is_filtered: true,
all_posts_filtered: false,
all_posts_hidden_nsfw: false,
})
} else {
match Post::fetch(&path, quarantined).await {
Ok((mut posts, after)) => {
let all_posts_filtered = filter_posts(&mut posts, &filters);
let all_posts_hidden_nsfw = posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
template(SubredditTemplate {
sub,
posts,
@ -127,6 +130,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
redirect_url,
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
})
}
Err(msg) => match msg.as_str() {