Change "any NSFW post" warning to "all NSFW post" warning

This commit is contained in:
sigaloid 2022-05-16 16:38:32 -04:00
parent e559929427
commit 5a359ede50
6 changed files with 22 additions and 22 deletions

View File

@ -42,8 +42,8 @@ struct SearchTemplate {
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place, /// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
/// and all fetched posts being filtered). /// and all fetched posts being filtered).
all_posts_filtered: bool, all_posts_filtered: bool,
/// Whether any 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)
any_posts_hidden_nsfw: bool, all_posts_hidden_nsfw: bool,
} }
// SERVICES // SERVICES
@ -102,13 +102,13 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
url, url,
is_filtered: true, is_filtered: true,
all_posts_filtered: false, all_posts_filtered: false,
any_posts_hidden_nsfw: false, all_posts_hidden_nsfw: 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 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 { template(SearchTemplate {
posts, posts,
subreddits, subreddits,
@ -126,7 +126,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
url, url,
is_filtered: false, is_filtered: false,
all_posts_filtered, all_posts_filtered,
any_posts_hidden_nsfw, all_posts_hidden_nsfw,
}) })
} }
Err(msg) => { Err(msg) => {

View File

@ -25,8 +25,8 @@ struct SubredditTemplate {
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place, /// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
/// and all fetched posts being filtered). /// and all fetched posts being filtered).
all_posts_filtered: bool, all_posts_filtered: bool,
/// Whether any 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)
any_posts_hidden_nsfw: bool, all_posts_hidden_nsfw: bool,
} }
#[derive(Template)] #[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 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 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); let filters = get_filters(&req);
// If all requested subs are filtered, we don't need to fetch posts. // 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, redirect_url,
is_filtered: true, is_filtered: true,
all_posts_filtered: false, all_posts_filtered: false,
any_posts_hidden_nsfw: false, all_posts_hidden_nsfw: 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 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 { template(SubredditTemplate {
sub, sub,
posts, posts,
@ -131,7 +131,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
redirect_url, redirect_url,
is_filtered: false, is_filtered: false,
all_posts_filtered, all_posts_filtered,
any_posts_hidden_nsfw, all_posts_hidden_nsfw,
}) })
} }
Err(msg) => match msg.as_str() { Err(msg) => match msg.as_str() {

View File

@ -25,8 +25,8 @@ struct UserTemplate {
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place, /// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
/// and all fetched posts being filtered). /// and all fetched posts being filtered).
all_posts_filtered: bool, all_posts_filtered: bool,
/// Whether any 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)
any_posts_hidden_nsfw: bool, all_posts_hidden_nsfw: bool,
} }
// FUNCTIONS // FUNCTIONS
@ -61,14 +61,14 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
redirect_url, redirect_url,
is_filtered: true, is_filtered: true,
all_posts_filtered: false, all_posts_filtered: false,
any_posts_hidden_nsfw: false, all_posts_hidden_nsfw: 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 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 { template(UserTemplate {
user, user,
posts, posts,
@ -80,7 +80,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
redirect_url, redirect_url,
is_filtered: false, is_filtered: false,
all_posts_filtered, all_posts_filtered,
any_posts_hidden_nsfw, all_posts_hidden_nsfw,
}) })
} }
// If there is an error show error page // If there is an error show error page

View File

@ -57,8 +57,8 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if any_posts_hidden_nsfw %} {% if all_posts_hidden_nsfw %}
<center>Some posts were 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 all_posts_filtered %} {% if all_posts_filtered %}

View File

@ -46,8 +46,8 @@
</form> </form>
{% endif %} {% endif %}
{% if any_posts_hidden_nsfw %} {% if all_posts_hidden_nsfw %}
<center>Some posts were 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 all_posts_filtered %} {% if all_posts_filtered %}

View File

@ -32,8 +32,8 @@
</button> </button>
</form> </form>
{% if any_posts_hidden_nsfw %} {% if all_posts_hidden_nsfw %}
<center>Some posts were 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 all_posts_filtered %} {% if all_posts_filtered %}