diff --git a/src/subreddit.rs b/src/subreddit.rs
index 0560e1b..8aea21b 100644
--- a/src/subreddit.rs
+++ b/src/subreddit.rs
@@ -145,6 +145,10 @@ pub async fn community(req: Request
) -> Result, String> {
let (_, all_posts_filtered) = filter_posts(&mut posts, &filters);
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");
+ if sort == "new" {
+ posts.sort_by(|a, b| b.created_ts.cmp(&a.created_ts));
+ posts.sort_by(|a, b| b.flags.stickied.cmp(&a.flags.stickied));
+ }
Ok(template(&SubredditTemplate {
sub,
posts,
diff --git a/src/utils.rs b/src/utils.rs
index ea0045d..5e8d83c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -425,8 +425,6 @@ impl Post {
ws_url: val(post, "websocket_url"),
});
}
- posts.sort_by(|a, b| b.created_ts.cmp(&a.created_ts));
- posts.sort_by(|a, b| b.flags.stickied.cmp(&a.flags.stickied));
Ok((posts, res["data"]["after"].as_str().unwrap_or_default().to_string()))
}
}