2024-02-16 14:36:46 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
newtypes::CommunityId,
|
|
|
|
source::{local_site::LocalSite, local_user::LocalUser},
|
|
|
|
ListingType,
|
|
|
|
SortType,
|
|
|
|
};
|
2022-11-28 14:29:33 +00:00
|
|
|
|
2023-07-03 09:01:41 +00:00
|
|
|
pub mod list_comments;
|
|
|
|
pub mod list_posts;
|
|
|
|
pub mod read_community;
|
|
|
|
pub mod read_person;
|
|
|
|
pub mod resolve_object;
|
|
|
|
pub mod search;
|
2023-10-11 14:47:22 +00:00
|
|
|
pub mod user_settings_backup;
|
2023-04-12 14:40:59 +00:00
|
|
|
|
|
|
|
/// Returns default listing type, depending if the query is for frontpage or community.
|
|
|
|
fn listing_type_with_default(
|
|
|
|
type_: Option<ListingType>,
|
2024-02-16 14:36:46 +00:00
|
|
|
local_user: Option<&LocalUser>,
|
2023-04-12 14:40:59 +00:00
|
|
|
local_site: &LocalSite,
|
|
|
|
community_id: Option<CommunityId>,
|
2024-02-16 14:36:46 +00:00
|
|
|
) -> ListingType {
|
2023-04-12 14:40:59 +00:00
|
|
|
// On frontpage use listing type from param or admin configured default
|
2024-02-16 14:36:46 +00:00
|
|
|
if community_id.is_none() {
|
|
|
|
type_.unwrap_or(
|
|
|
|
local_user
|
|
|
|
.map(|u| u.default_listing_type)
|
|
|
|
.unwrap_or(local_site.default_post_listing_type),
|
|
|
|
)
|
2023-04-12 14:40:59 +00:00
|
|
|
} else {
|
|
|
|
// inside of community show everything
|
|
|
|
ListingType::All
|
2024-02-16 14:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a default instance-level sort type, if none is given by the user.
|
|
|
|
/// Order is type, local user default, then site default.
|
|
|
|
fn sort_type_with_default(
|
|
|
|
type_: Option<SortType>,
|
|
|
|
local_user: Option<&LocalUser>,
|
|
|
|
local_site: &LocalSite,
|
|
|
|
) -> SortType {
|
|
|
|
type_.unwrap_or(
|
|
|
|
local_user
|
|
|
|
.map(|u| u.default_sort_type)
|
|
|
|
.unwrap_or(local_site.default_sort_type),
|
|
|
|
)
|
2023-04-12 14:40:59 +00:00
|
|
|
}
|