]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/api/mod.rs
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / crates / apub / src / api / mod.rs
index 233f72f0220ab74a1ad8241b1e7638cd751f039f..9099dbd09d04445bb83e25ef1ec28268182d5f00 100644 (file)
@@ -1,5 +1,6 @@
-use actix_web::web::Data;
+use activitypub_federation::config::Data;
 use lemmy_api_common::context::LemmyContext;
+use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 mod list_comments;
@@ -9,7 +10,7 @@ mod read_person;
 mod resolve_object;
 mod search;
 
-#[async_trait::async_trait(?Send)]
+#[async_trait::async_trait]
 pub trait PerformApub {
   type Response: serde::ser::Serialize + Send;
 
@@ -19,3 +20,19 @@ pub trait PerformApub {
     websocket_id: Option<ConnectionId>,
   ) -> Result<Self::Response, LemmyError>;
 }
+
+/// 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() {
+    type_.unwrap_or(local_site.default_post_listing_type)
+  } else {
+    // inside of community show everything
+    ListingType::All
+  };
+  Ok(listing_type)
+}