mirror of https://github.com/spikecodes/libreddit
Change "any NSFW post" warning to "all NSFW post" warning
This commit is contained in:
parent
e559929427
commit
5a359ede50
|
@ -42,8 +42,8 @@ struct SearchTemplate {
|
|||
/// 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 any posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
any_posts_hidden_nsfw: bool,
|
||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
all_posts_hidden_nsfw: bool,
|
||||
}
|
||||
|
||||
// SERVICES
|
||||
|
@ -102,13 +102,13 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
url,
|
||||
is_filtered: true,
|
||||
all_posts_filtered: false,
|
||||
any_posts_hidden_nsfw: 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 any_posts_hidden_nsfw = posts.iter().any(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
let all_posts_hidden_nsfw = posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
template(SearchTemplate {
|
||||
posts,
|
||||
subreddits,
|
||||
|
@ -126,7 +126,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
url,
|
||||
is_filtered: false,
|
||||
all_posts_filtered,
|
||||
any_posts_hidden_nsfw,
|
||||
all_posts_hidden_nsfw,
|
||||
})
|
||||
}
|
||||
Err(msg) => {
|
||||
|
|
|
@ -25,8 +25,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 any posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
any_posts_hidden_nsfw: bool,
|
||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
all_posts_hidden_nsfw: bool,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
@ -99,7 +99,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
|
||||
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub_name.clone(), sort, req.uri().query().unwrap_or_default());
|
||||
let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str()));
|
||||
let redirect_url = url[1..].replace('?', "%3F").replace('&', "%26").replace('+',"%2B");
|
||||
let redirect_url = url[1..].replace('?', "%3F").replace('&', "%26").replace('+', "%2B");
|
||||
let filters = get_filters(&req);
|
||||
|
||||
// If all requested subs are filtered, we don't need to fetch posts.
|
||||
|
@ -114,13 +114,13 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
redirect_url,
|
||||
is_filtered: true,
|
||||
all_posts_filtered: false,
|
||||
any_posts_hidden_nsfw: 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 any_posts_hidden_nsfw = posts.iter().any(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
let all_posts_hidden_nsfw = posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
template(SubredditTemplate {
|
||||
sub,
|
||||
posts,
|
||||
|
@ -131,7 +131,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
redirect_url,
|
||||
is_filtered: false,
|
||||
all_posts_filtered,
|
||||
any_posts_hidden_nsfw,
|
||||
all_posts_hidden_nsfw,
|
||||
})
|
||||
}
|
||||
Err(msg) => match msg.as_str() {
|
||||
|
|
10
src/user.rs
10
src/user.rs
|
@ -25,8 +25,8 @@ struct UserTemplate {
|
|||
/// 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 any posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
any_posts_hidden_nsfw: bool,
|
||||
/// Whether all posts were hidden because they are NSFW (and user has disabled show NSFW)
|
||||
all_posts_hidden_nsfw: bool,
|
||||
}
|
||||
|
||||
// FUNCTIONS
|
||||
|
@ -61,14 +61,14 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
redirect_url,
|
||||
is_filtered: true,
|
||||
all_posts_filtered: false,
|
||||
any_posts_hidden_nsfw: false,
|
||||
all_posts_hidden_nsfw: 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 any_posts_hidden_nsfw = posts.iter().any(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
let all_posts_hidden_nsfw = posts.iter().all(|p| p.flags.nsfw) && setting(&req, "show_nsfw") != "on";
|
||||
template(UserTemplate {
|
||||
user,
|
||||
posts,
|
||||
|
@ -80,7 +80,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||
redirect_url,
|
||||
is_filtered: false,
|
||||
all_posts_filtered,
|
||||
any_posts_hidden_nsfw,
|
||||
all_posts_hidden_nsfw,
|
||||
})
|
||||
}
|
||||
// If there is an error show error page
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if any_posts_hidden_nsfw %}
|
||||
<center>Some posts were hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% if all_posts_hidden_nsfw %}
|
||||
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% endif %}
|
||||
|
||||
{% if all_posts_filtered %}
|
||||
|
|
|
@ -46,8 +46,8 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if any_posts_hidden_nsfw %}
|
||||
<center>Some posts were hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% if all_posts_hidden_nsfw %}
|
||||
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% endif %}
|
||||
|
||||
{% if all_posts_filtered %}
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
</button>
|
||||
</form>
|
||||
|
||||
{% if any_posts_hidden_nsfw %}
|
||||
<center>Some posts were hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% if all_posts_hidden_nsfw %}
|
||||
<center>All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.</center>
|
||||
{% endif %}
|
||||
|
||||
{% if all_posts_filtered %}
|
||||
|
|
Loading…
Reference in New Issue