From 67a890cab30e899650d40aa5c3d5416d3958c723 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 2 Jul 2024 08:04:27 -0400 Subject: [PATCH] fix(posts): fix sort call on new (#171) --- src/subreddit.rs | 4 ++++ src/utils.rs | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) 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())) } }