]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/http/community.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / apub / src / http / community.rs
index 4ae50bb05fcc0b1a6c36061315aedf5c917b3756..18ad860b0adbd6a626167640a93e0475c32183f9 100644 (file)
@@ -18,7 +18,7 @@ use activitypub_federation::{
 use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
 use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{source::community::Community, traits::ApubActor};
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorType};
 use serde::Deserialize;
 
 #[derive(Deserialize)]
@@ -33,16 +33,16 @@ pub(crate) async fn get_apub_community_http(
   context: Data<LemmyContext>,
 ) -> Result<HttpResponse, LemmyError> {
   let community: ApubCommunity =
-    Community::read_from_name(context.pool(), &info.community_name, true)
+    Community::read_from_name(&mut context.pool(), &info.community_name, true)
       .await?
       .into();
 
   if !community.deleted && !community.removed {
     let apub = community.into_json(&context).await?;
 
-    Ok(create_apub_response(&apub))
+    create_apub_response(&apub)
   } else {
-    Ok(create_apub_tombstone_response(community.actor_id.clone()))
+    create_apub_tombstone_response(community.actor_id.clone())
   }
 }
 
@@ -64,9 +64,10 @@ pub(crate) async fn get_apub_community_followers(
   info: web::Path<CommunityQuery>,
   context: Data<LemmyContext>,
 ) -> Result<HttpResponse, LemmyError> {
-  let community = Community::read_from_name(context.pool(), &info.community_name, false).await?;
+  let community =
+    Community::read_from_name(&mut context.pool(), &info.community_name, false).await?;
   let followers = GroupFollowers::new(community, &context).await?;
-  Ok(create_apub_response(&followers))
+  create_apub_response(&followers)
 }
 
 /// Returns the community outbox, which is populated by a maximum of 20 posts (but no other
@@ -76,14 +77,14 @@ pub(crate) async fn get_apub_community_outbox(
   context: Data<LemmyContext>,
 ) -> Result<HttpResponse, LemmyError> {
   let community: ApubCommunity =
-    Community::read_from_name(context.pool(), &info.community_name, false)
+    Community::read_from_name(&mut context.pool(), &info.community_name, false)
       .await?
       .into();
   if community.deleted || community.removed {
-    return Err(LemmyError::from_message("deleted"));
+    return Err(LemmyErrorType::Deleted)?;
   }
   let outbox = ApubCommunityOutbox::read_local(&community, &context).await?;
-  Ok(create_apub_response(&outbox))
+  create_apub_response(&outbox)
 }
 
 #[tracing::instrument(skip_all)]
@@ -92,14 +93,14 @@ pub(crate) async fn get_apub_community_moderators(
   context: Data<LemmyContext>,
 ) -> Result<HttpResponse, LemmyError> {
   let community: ApubCommunity =
-    Community::read_from_name(context.pool(), &info.community_name, false)
+    Community::read_from_name(&mut context.pool(), &info.community_name, false)
       .await?
       .into();
   if community.deleted || community.removed {
-    return Err(LemmyError::from_message("deleted"));
+    return Err(LemmyErrorType::Deleted)?;
   }
   let moderators = ApubCommunityModerators::read_local(&community, &context).await?;
-  Ok(create_apub_response(&moderators))
+  create_apub_response(&moderators)
 }
 
 /// Returns collection of featured (stickied) posts.
@@ -108,12 +109,12 @@ pub(crate) async fn get_apub_community_featured(
   context: Data<LemmyContext>,
 ) -> Result<HttpResponse, LemmyError> {
   let community: ApubCommunity =
-    Community::read_from_name(context.pool(), &info.community_name, false)
+    Community::read_from_name(&mut context.pool(), &info.community_name, false)
       .await?
       .into();
   if community.deleted || community.removed {
-    return Err(LemmyError::from_message("deleted"));
+    return Err(LemmyErrorType::Deleted)?;
   }
   let featured = ApubCommunityFeatured::read_local(&community, &context).await?;
-  Ok(create_apub_response(&featured))
+  create_apub_response(&featured)
 }