From: Dessalines Date: Mon, 3 Jul 2023 17:09:15 +0000 (-0400) Subject: Adding rest of community sorts. Fixes #3374 (#3376) X-Git-Url: http://these/git/%7B%24%7B%60data:application/static/%7B%7D/inbox?a=commitdiff_plain;h=935b0bf0480db29dc632c64e3cc50e593eb08a30;p=lemmy.git Adding rest of community sorts. Fixes #3374 (#3376) * Adding rest of community sorts. Fixes #3374 * Addressing PR comments. --- diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 826a0e88..94bcdaf9 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -133,6 +133,8 @@ pub struct CommunityQuery<'a> { impl<'a> CommunityQuery<'a> { pub async fn list(self) -> Result, Error> { + use SortType::*; + let conn = &mut get_conn(self.pool).await?; // The left join below will return None in this case @@ -181,14 +183,22 @@ impl<'a> CommunityQuery<'a> { .or(community_follower::person_id.eq(person_id_join)), ); } - - match self.sort.unwrap_or(SortType::Hot) { - SortType::New => query = query.order_by(community::published.desc()), - SortType::TopAll => query = query.order_by(community_aggregates::subscribers.desc()), - SortType::TopMonth => query = query.order_by(community_aggregates::users_active_month.desc()), - SortType::Hot => query = query.order_by(community_aggregates::hot_rank.desc()), - // Covers all other sorts - _ => query = query.order_by(community_aggregates::users_active_month.desc()), + match self.sort.unwrap_or(Hot) { + Hot | Active => query = query.order_by(community_aggregates::hot_rank.desc()), + NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => { + query = query.order_by(community_aggregates::users_active_day.desc()) + } + New => query = query.order_by(community::published.desc()), + Old => query = query.order_by(community::published.asc()), + MostComments => query = query.order_by(community_aggregates::comments.desc()), + TopAll | TopYear | TopNineMonths => { + query = query.order_by(community_aggregates::subscribers.desc()) + } + TopSixMonths | TopThreeMonths => { + query = query.order_by(community_aggregates::users_active_half_year.desc()) + } + TopMonth => query = query.order_by(community_aggregates::users_active_month.desc()), + TopWeek => query = query.order_by(community_aggregates::users_active_week.desc()), }; if let Some(listing_type) = self.listing_type {