mirror of https://github.com/spikecodes/libreddit
Merge branch 'master' of github.com:libreddit/libreddit into ferrit-nsfw
This commit is contained in:
commit
d2d0b23930
|
@ -44,6 +44,7 @@ struct SearchTemplate {
|
||||||
all_posts_filtered: bool,
|
all_posts_filtered: bool,
|
||||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||||
all_posts_hidden_nsfw: bool,
|
all_posts_hidden_nsfw: bool,
|
||||||
|
no_posts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
|
@ -108,12 +109,14 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: true,
|
is_filtered: true,
|
||||||
all_posts_filtered: false,
|
all_posts_filtered: false,
|
||||||
all_posts_hidden_nsfw: false,
|
all_posts_hidden_nsfw: false,
|
||||||
|
no_posts: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
match Post::fetch(&path, quarantined).await {
|
match Post::fetch(&path, quarantined).await {
|
||||||
Ok((mut posts, after)) => {
|
Ok((mut posts, after)) => {
|
||||||
let (_, all_posts_filtered) = filter_posts(&mut posts, &filters);
|
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 {
|
template(SearchTemplate {
|
||||||
posts,
|
posts,
|
||||||
subreddits,
|
subreddits,
|
||||||
|
@ -132,6 +135,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: false,
|
is_filtered: false,
|
||||||
all_posts_filtered,
|
all_posts_filtered,
|
||||||
all_posts_hidden_nsfw,
|
all_posts_hidden_nsfw,
|
||||||
|
no_posts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
|
|
|
@ -26,6 +26,7 @@ struct SubredditTemplate {
|
||||||
all_posts_filtered: bool,
|
all_posts_filtered: bool,
|
||||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||||
all_posts_hidden_nsfw: bool,
|
all_posts_hidden_nsfw: bool,
|
||||||
|
no_posts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -120,12 +121,14 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: true,
|
is_filtered: true,
|
||||||
all_posts_filtered: false,
|
all_posts_filtered: false,
|
||||||
all_posts_hidden_nsfw: false,
|
all_posts_hidden_nsfw: false,
|
||||||
|
no_posts: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
match Post::fetch(&path, quarantined).await {
|
match Post::fetch(&path, quarantined).await {
|
||||||
Ok((mut posts, after)) => {
|
Ok((mut posts, after)) => {
|
||||||
let (_, all_posts_filtered) = filter_posts(&mut posts, &filters);
|
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 {
|
template(SubredditTemplate {
|
||||||
sub,
|
sub,
|
||||||
posts,
|
posts,
|
||||||
|
@ -137,6 +140,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: false,
|
is_filtered: false,
|
||||||
all_posts_filtered,
|
all_posts_filtered,
|
||||||
all_posts_hidden_nsfw,
|
all_posts_hidden_nsfw,
|
||||||
|
no_posts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(msg) => match msg.as_str() {
|
Err(msg) => match msg.as_str() {
|
||||||
|
|
|
@ -26,6 +26,7 @@ struct UserTemplate {
|
||||||
all_posts_filtered: bool,
|
all_posts_filtered: bool,
|
||||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||||
all_posts_hidden_nsfw: bool,
|
all_posts_hidden_nsfw: bool,
|
||||||
|
no_posts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
|
@ -70,13 +71,15 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: true,
|
is_filtered: true,
|
||||||
all_posts_filtered: false,
|
all_posts_filtered: false,
|
||||||
all_posts_hidden_nsfw: false,
|
all_posts_hidden_nsfw: false,
|
||||||
|
no_posts: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Request user posts/comments from Reddit
|
// Request user posts/comments from Reddit
|
||||||
match Post::fetch(&path, false).await {
|
match Post::fetch(&path, false).await {
|
||||||
Ok((mut posts, after)) => {
|
Ok((mut posts, after)) => {
|
||||||
let (_, all_posts_filtered) = filter_posts(&mut posts, &filters);
|
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 {
|
template(UserTemplate {
|
||||||
user,
|
user,
|
||||||
posts,
|
posts,
|
||||||
|
@ -89,6 +92,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
is_filtered: false,
|
is_filtered: false,
|
||||||
all_posts_filtered,
|
all_posts_filtered,
|
||||||
all_posts_hidden_nsfw,
|
all_posts_hidden_nsfw,
|
||||||
|
no_posts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// If there is an error show error page
|
// If there is an error show error page
|
||||||
|
|
|
@ -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>
|
<span class="listing_warn">All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if no_posts %}
|
||||||
|
<center>No posts were found.</center>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if all_posts_filtered %}
|
{% if all_posts_filtered %}
|
||||||
<span class="listing_warn">(All content on this page has been filtered)</span>
|
<span class="listing_warn">(All content on this page has been filtered)</span>
|
||||||
{% else if is_filtered %}
|
{% else if is_filtered %}
|
||||||
|
|
|
@ -50,6 +50,10 @@
|
||||||
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if no_posts %}
|
||||||
|
<center>No posts were found.</center>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if all_posts_filtered %}
|
{% if all_posts_filtered %}
|
||||||
<center>(All content on this page has been filtered)</center>
|
<center>(All content on this page has been filtered)</center>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if no_posts %}
|
||||||
|
<center>No posts were found.</center>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if all_posts_filtered %}
|
{% if all_posts_filtered %}
|
||||||
<center>(All content on this page has been filtered)</center>
|
<center>(All content on this page has been filtered)</center>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Reference in New Issue