diff --git a/src/search.rs b/src/search.rs
index 0a62b06..9fbe77a 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -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
@@ -103,12 +104,14 @@ pub async fn find(req: Request
) -> Result, 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,
@@ -127,6 +130,7 @@ pub async fn find(req: Request) -> Result, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
+ no_posts,
})
}
Err(msg) => {
diff --git a/src/subreddit.rs b/src/subreddit.rs
index 4aff027..ef511c2 100644
--- a/src/subreddit.rs
+++ b/src/subreddit.rs
@@ -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)]
@@ -114,12 +115,14 @@ pub async fn community(req: Request) -> Result, 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,
@@ -131,6 +134,7 @@ pub async fn community(req: Request) -> Result, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
+ no_posts,
})
}
Err(msg) => match msg.as_str() {
diff --git a/src/user.rs b/src/user.rs
index 8c0540c..6c991ef 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -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
@@ -61,13 +62,15 @@ pub async fn profile(req: Request) -> Result, 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,
@@ -80,6 +83,7 @@ pub async fn profile(req: Request) -> Result, String> {
is_filtered: false,
all_posts_filtered,
all_posts_hidden_nsfw,
+ no_posts,
})
}
// If there is an error show error page
diff --git a/templates/search.html b/templates/search.html
index 43fadb4..b9742f6 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -61,6 +61,10 @@
All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.
{% endif %}
+ {% if no_posts %}
+ No posts were found.
+ {% endif %}
+
{% if all_posts_filtered %}
(All content on this page has been filtered)
{% else if is_filtered %}
diff --git a/templates/subreddit.html b/templates/subreddit.html
index 4fdad65..9ad1932 100644
--- a/templates/subreddit.html
+++ b/templates/subreddit.html
@@ -50,6 +50,10 @@
All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.
{% endif %}
+ {% if no_posts %}
+ No posts were found.
+ {% endif %}
+
{% if all_posts_filtered %}
(All content on this page has been filtered)
{% else %}
diff --git a/templates/user.html b/templates/user.html
index 04dc4e6..a72cce0 100644
--- a/templates/user.html
+++ b/templates/user.html
@@ -36,6 +36,10 @@
All posts are hidden because they are NSFW. Enable "Show NSFW posts" in settings to view.
{% endif %}
+ {% if no_posts %}
+ No posts were found.
+ {% endif %}
+
{% if all_posts_filtered %}
(All content on this page has been filtered)
{% else %}