From befa9339397d775e6599fe9ee419daf12939d82c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 15 Feb 2024 13:48:23 -0500 Subject: [PATCH] Put user sort before site sort. --- crates/apub/src/api/list_comments.rs | 1 + crates/apub/src/api/list_posts.rs | 8 +++++++- crates/apub/src/api/mod.rs | 22 ++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/apub/src/api/list_comments.rs b/crates/apub/src/api/list_comments.rs index 7d0327465..73ac5c3f0 100644 --- a/crates/apub/src/api/list_comments.rs +++ b/crates/apub/src/api/list_comments.rs @@ -49,6 +49,7 @@ pub async fn list_comments( let listing_type = Some(listing_type_with_default( data.type_, &local_site, + local_user_view.as_ref().map(|u| &u.local_user), community_id, )); diff --git a/crates/apub/src/api/list_posts.rs b/crates/apub/src/api/list_posts.rs index 633f5b48c..bcba19334 100644 --- a/crates/apub/src/api/list_posts.rs +++ b/crates/apub/src/api/list_posts.rs @@ -43,13 +43,19 @@ pub async fn list_posts( return Err(LemmyError::from(LemmyErrorType::ContradictingFilters)); } + let local_user_ref = local_user_view.as_ref().map(|u| &u.local_user); let listing_type = Some(listing_type_with_default( data.type_, &local_site, + local_user_ref, community_id, )); - let sort = Some(sort_type_with_default(data.sort, &local_site)); + let sort = Some(sort_type_with_default( + data.sort, + &local_site, + local_user_ref, + )); // parse pagination token let page_after = if let Some(pa) = &data.page_cursor { diff --git a/crates/apub/src/api/mod.rs b/crates/apub/src/api/mod.rs index b85c5431e..a36f57f16 100644 --- a/crates/apub/src/api/mod.rs +++ b/crates/apub/src/api/mod.rs @@ -1,6 +1,6 @@ use lemmy_db_schema::{ newtypes::CommunityId, - source::local_site::LocalSite, + source::{local_site::LocalSite, local_user::LocalUser}, ListingType, SortType, }; @@ -17,11 +17,16 @@ pub mod user_settings_backup; fn listing_type_with_default( type_: Option, local_site: &LocalSite, + local_user: Option<&LocalUser>, community_id: Option, ) -> ListingType { // On frontpage use listing type from param or admin configured default if community_id.is_none() { - type_.unwrap_or(local_site.default_post_listing_type) + type_.unwrap_or( + local_user + .map(|u| u.default_listing_type) + .unwrap_or(local_site.default_post_listing_type), + ) } else { // inside of community show everything ListingType::All @@ -29,6 +34,15 @@ fn listing_type_with_default( } /// Returns a default instance-level sort type, if none is given by the user. -fn sort_type_with_default(type_: Option, local_site: &LocalSite) -> SortType { - type_.unwrap_or(local_site.default_sort_type) +/// Order is type, local user default, then site default. +fn sort_type_with_default( + type_: Option, + local_site: &LocalSite, + local_user: Option<&LocalUser>, +) -> SortType { + type_.unwrap_or( + local_user + .map(|u| u.default_sort_type) + .unwrap_or(local_site.default_sort_type), + ) }