]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/receive/community.rs
Refactor activitypub code
[lemmy.git] / crates / apub / src / activities / receive / community.rs
index cf85ad10609269e5f85b6d281ae85f52966e9548..48f6b295dd6fda6e0c656df1e9c4fd2be2459d05 100644 (file)
@@ -1,19 +1,9 @@
-use crate::{
-  activities::receive::verify_activity_domains_valid,
-  inbox::verify_is_addressed_to_public,
-};
-use activitystreams::{
-  activity::{ActorAndObjectRefExt, Delete, Remove, Undo},
-  base::{AnyBase, ExtendsExt},
-};
-use anyhow::Context;
 use lemmy_api_structs::{blocking, community::CommunityResponse};
-use lemmy_db_queries::{source::community::Community_, ApubObject};
+use lemmy_db_queries::source::community::Community_;
 use lemmy_db_schema::source::community::Community;
 use lemmy_db_views_actor::community_view::CommunityView;
-use lemmy_utils::{location_info, LemmyError};
+use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
-use url::Url;
 
 pub(crate) async fn receive_delete_community(
   context: &LemmyContext,
@@ -45,23 +35,8 @@ pub(crate) async fn receive_delete_community(
 
 pub(crate) async fn receive_remove_community(
   context: &LemmyContext,
-  activity: AnyBase,
-  expected_domain: &Url,
+  community: Community,
 ) -> Result<(), LemmyError> {
-  let remove = Remove::from_any_base(activity)?.context(location_info!())?;
-  verify_activity_domains_valid(&remove, expected_domain, true)?;
-  verify_is_addressed_to_public(&remove)?;
-
-  let community_uri = remove
-    .object()
-    .to_owned()
-    .single_xsd_any_uri()
-    .context(location_info!())?;
-  let community = blocking(context.pool(), move |conn| {
-    Community::read_from_apub_id(conn, &community_uri.into())
-  })
-  .await??;
-
   let removed_community = blocking(context.pool(), move |conn| {
     Community::update_removed(conn, community.id, true)
   })
@@ -88,16 +63,8 @@ pub(crate) async fn receive_remove_community(
 
 pub(crate) async fn receive_undo_delete_community(
   context: &LemmyContext,
-  undo: Undo,
   community: Community,
-  expected_domain: &Url,
 ) -> Result<(), LemmyError> {
-  verify_is_addressed_to_public(&undo)?;
-  let inner = undo.object().to_owned().one().context(location_info!())?;
-  let delete = Delete::from_any_base(inner)?.context(location_info!())?;
-  verify_activity_domains_valid(&delete, expected_domain, true)?;
-  verify_is_addressed_to_public(&delete)?;
-
   let deleted_community = blocking(context.pool(), move |conn| {
     Community::update_deleted(conn, community.id, false)
   })
@@ -124,26 +91,8 @@ pub(crate) async fn receive_undo_delete_community(
 
 pub(crate) async fn receive_undo_remove_community(
   context: &LemmyContext,
-  undo: Undo,
-  expected_domain: &Url,
+  community: Community,
 ) -> Result<(), LemmyError> {
-  verify_is_addressed_to_public(&undo)?;
-
-  let inner = undo.object().to_owned().one().context(location_info!())?;
-  let remove = Remove::from_any_base(inner)?.context(location_info!())?;
-  verify_activity_domains_valid(&remove, &expected_domain, true)?;
-  verify_is_addressed_to_public(&remove)?;
-
-  let community_uri = remove
-    .object()
-    .to_owned()
-    .single_xsd_any_uri()
-    .context(location_info!())?;
-  let community = blocking(context.pool(), move |conn| {
-    Community::read_from_apub_id(conn, &community_uri.into())
-  })
-  .await??;
-
   let removed_community = blocking(context.pool(), move |conn| {
     Community::update_removed(conn, community.id, false)
   })