mirror of https://github.com/LemmyNet/lemmy.git
Put user sort before site sort.
parent
59111c0379
commit
befa933939
|
@ -49,6 +49,7 @@ pub async fn list_comments(
|
||||||
let listing_type = Some(listing_type_with_default(
|
let listing_type = Some(listing_type_with_default(
|
||||||
data.type_,
|
data.type_,
|
||||||
&local_site,
|
&local_site,
|
||||||
|
local_user_view.as_ref().map(|u| &u.local_user),
|
||||||
community_id,
|
community_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,19 @@ pub async fn list_posts(
|
||||||
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
|
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(
|
let listing_type = Some(listing_type_with_default(
|
||||||
data.type_,
|
data.type_,
|
||||||
&local_site,
|
&local_site,
|
||||||
|
local_user_ref,
|
||||||
community_id,
|
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
|
// parse pagination token
|
||||||
let page_after = if let Some(pa) = &data.page_cursor {
|
let page_after = if let Some(pa) = &data.page_cursor {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
source::local_site::LocalSite,
|
source::{local_site::LocalSite, local_user::LocalUser},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -17,11 +17,16 @@ pub mod user_settings_backup;
|
||||||
fn listing_type_with_default(
|
fn listing_type_with_default(
|
||||||
type_: Option<ListingType>,
|
type_: Option<ListingType>,
|
||||||
local_site: &LocalSite,
|
local_site: &LocalSite,
|
||||||
|
local_user: Option<&LocalUser>,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> ListingType {
|
) -> ListingType {
|
||||||
// On frontpage use listing type from param or admin configured default
|
// On frontpage use listing type from param or admin configured default
|
||||||
if community_id.is_none() {
|
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 {
|
} else {
|
||||||
// inside of community show everything
|
// inside of community show everything
|
||||||
ListingType::All
|
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.
|
/// Returns a default instance-level sort type, if none is given by the user.
|
||||||
fn sort_type_with_default(type_: Option<SortType>, local_site: &LocalSite) -> SortType {
|
/// Order is type, local user default, then site default.
|
||||||
type_.unwrap_or(local_site.default_sort_type)
|
fn sort_type_with_default(
|
||||||
|
type_: Option<SortType>,
|
||||||
|
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),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue