]> Untitled Git - lemmy.git/blob - crates/apub/src/api/mod.rs
Make path to local lemmy-ui use correct relative path (#2817)
[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 use std::str::FromStr;
6
7 mod list_comments;
8 mod list_posts;
9 mod read_community;
10 mod read_person;
11 mod resolve_object;
12 mod search;
13
14 #[async_trait::async_trait]
15 pub trait PerformApub {
16   type Response: serde::ser::Serialize + Send;
17
18   async fn perform(
19     &self,
20     context: &Data<LemmyContext>,
21     websocket_id: Option<ConnectionId>,
22   ) -> Result<Self::Response, LemmyError>;
23 }
24
25 /// Returns default listing type, depending if the query is for frontpage or community.
26 fn listing_type_with_default(
27   type_: Option<ListingType>,
28   local_site: &LocalSite,
29   community_id: Option<CommunityId>,
30 ) -> Result<ListingType, LemmyError> {
31   // On frontpage use listing type from param or admin configured default
32   let listing_type = if community_id.is_none() {
33     type_.unwrap_or(ListingType::from_str(
34       &local_site.default_post_listing_type,
35     )?)
36   } else {
37     // inside of community show everything
38     ListingType::All
39   };
40   Ok(listing_type)
41 }