]> Untitled Git - lemmy.git/blob - crates/apub/src/api/mod.rs
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / crates / apub / src / api / mod.rs
1 use activitypub_federation::config::Data;
2 use lemmy_api_common::context::LemmyContext;
3 use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
4 use lemmy_utils::{error::LemmyError, ConnectionId};
5
6 mod list_comments;
7 mod list_posts;
8 mod read_community;
9 mod read_person;
10 mod resolve_object;
11 mod search;
12
13 #[async_trait::async_trait]
14 pub trait PerformApub {
15   type Response: serde::ser::Serialize + Send;
16
17   async fn perform(
18     &self,
19     context: &Data<LemmyContext>,
20     websocket_id: Option<ConnectionId>,
21   ) -> Result<Self::Response, LemmyError>;
22 }
23
24 /// Returns default listing type, depending if the query is for frontpage or community.
25 fn listing_type_with_default(
26   type_: Option<ListingType>,
27   local_site: &LocalSite,
28   community_id: Option<CommunityId>,
29 ) -> Result<ListingType, LemmyError> {
30   // On frontpage use listing type from param or admin configured default
31   let listing_type = if community_id.is_none() {
32     type_.unwrap_or(local_site.default_post_listing_type)
33   } else {
34     // inside of community show everything
35     ListingType::All
36   };
37   Ok(listing_type)
38 }