mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
* Adding rest of community sorts. Fixes #3374 * Addressing PR comments.
This commit is contained in:
parent
e1494d4683
commit
935b0bf048
1 changed files with 18 additions and 8 deletions
|
@ -133,6 +133,8 @@ pub struct CommunityQuery<'a> {
|
||||||
|
|
||||||
impl<'a> CommunityQuery<'a> {
|
impl<'a> CommunityQuery<'a> {
|
||||||
pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
|
pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
|
||||||
|
use SortType::*;
|
||||||
|
|
||||||
let conn = &mut get_conn(self.pool).await?;
|
let conn = &mut get_conn(self.pool).await?;
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// 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)),
|
.or(community_follower::person_id.eq(person_id_join)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
match self.sort.unwrap_or(Hot) {
|
||||||
match self.sort.unwrap_or(SortType::Hot) {
|
Hot | Active => query = query.order_by(community_aggregates::hot_rank.desc()),
|
||||||
SortType::New => query = query.order_by(community::published.desc()),
|
NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => {
|
||||||
SortType::TopAll => query = query.order_by(community_aggregates::subscribers.desc()),
|
query = query.order_by(community_aggregates::users_active_day.desc())
|
||||||
SortType::TopMonth => query = query.order_by(community_aggregates::users_active_month.desc()),
|
}
|
||||||
SortType::Hot => query = query.order_by(community_aggregates::hot_rank.desc()),
|
New => query = query.order_by(community::published.desc()),
|
||||||
// Covers all other sorts
|
Old => query = query.order_by(community::published.asc()),
|
||||||
_ => query = query.order_by(community_aggregates::users_active_month.desc()),
|
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 {
|
if let Some(listing_type) = self.listing_type {
|
||||||
|
|
Loading…
Reference in a new issue