2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::config::Data;
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2023-04-12 14:40:59 +00:00
|
|
|
use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-11-28 14:29:33 +00:00
|
|
|
|
|
|
|
mod list_comments;
|
|
|
|
mod list_posts;
|
|
|
|
mod read_community;
|
|
|
|
mod read_person;
|
|
|
|
mod resolve_object;
|
|
|
|
mod search;
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2022-11-28 14:29:33 +00:00
|
|
|
pub trait PerformApub {
|
|
|
|
type Response: serde::ser::Serialize + Send;
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
|
2022-11-28 14:29:33 +00:00
|
|
|
}
|
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>,
|
|
|
|
local_site: &LocalSite,
|
|
|
|
community_id: Option<CommunityId>,
|
|
|
|
) -> Result<ListingType, LemmyError> {
|
|
|
|
// On frontpage use listing type from param or admin configured default
|
|
|
|
let listing_type = if community_id.is_none() {
|
2023-04-17 19:19:51 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
Ok(listing_type)
|
|
|
|
}
|