Merge branch 'master' of github.com:libreddit/libreddit into ferrit-nsfw

This commit is contained in:
Daniel Valentine 2022-12-31 20:21:45 -07:00
commit d2d0b23930
No known key found for this signature in database
GPG Key ID: C82492E4FF813823
6 changed files with 27 additions and 3 deletions

View File

@ -44,6 +44,7 @@ struct SearchTemplate {
all_posts_filtered: bool,
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
all_posts_hidden_nsfw: bool,
no_posts: bool,
}
// SERVICES
@ -108,12 +109,14 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: true,
all_posts_filtered: false,
all_posts_hidden_nsfw: false,
no_posts: 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";
let no_posts = posts.is_empty();
let all_posts_hidden_nsfw = !no_posts && (posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on");
template(SearchTemplate {
posts,
subreddits,
@ -132,6 +135,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
no_posts,
})
}
Err(msg) => {

View File

@ -26,6 +26,7 @@ struct SubredditTemplate {
all_posts_filtered: bool,
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
all_posts_hidden_nsfw: bool,
no_posts: bool,
}
#[derive(Template)]
@ -120,12 +121,14 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: true,
all_posts_filtered: false,
all_posts_hidden_nsfw: false,
no_posts: 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";
let no_posts = posts.is_empty();
let all_posts_hidden_nsfw = !no_posts && (posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on");
template(SubredditTemplate {
sub,
posts,
@ -137,6 +140,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
no_posts,
})
}
Err(msg) => match msg.as_str() {

View File

@ -26,6 +26,7 @@ struct UserTemplate {
all_posts_filtered: bool,
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
all_posts_hidden_nsfw: bool,
no_posts: bool,
}
// FUNCTIONS
@ -70,13 +71,15 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: true,
all_posts_filtered: false,
all_posts_hidden_nsfw: false,
no_posts: false,
})
} else {
// Request user posts/comments from Reddit
match Post::fetch(&path, false).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";
let no_posts = posts.is_empty();
let all_posts_hidden_nsfw = !no_posts && (posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on");
template(UserTemplate {
user,
posts,
@ -89,6 +92,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
no_posts,
})
}
// If there is an error show error page

View File

@ -61,6 +61,10 @@
<span class="listing_warn">All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</span>
{% endif %}
{% if no_posts %}
<center>No posts were found.</center>
{% endif %}
{% if all_posts_filtered %}
<span class="listing_warn">(All content on this page has been filtered)</span>
{% else if is_filtered %}

View File

@ -50,6 +50,10 @@
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
{% endif %}
{% if no_posts %}
<center>No posts were found.</center>
{% endif %}
{% if all_posts_filtered %}
<center>(All content on this page has been filtered)</center>
{% else %}

View File

@ -36,6 +36,10 @@
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
{% endif %}
{% if no_posts %}
<center>No posts were found.</center>
{% endif %}
{% if all_posts_filtered %}
<center>(All content on this page has been filtered)</center>
{% else %}