]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/community/announce.rs
Rewrite fetcher (#1792)
[lemmy.git] / crates / apub / src / activities / community / announce.rs
index 9cde8a43cc0f1254c76371886d6d1abc9eba0979..96797c8ffbbbee4439b6682ad9409b101c9cb5ff 100644 (file)
@@ -5,63 +5,70 @@ use crate::{
       add_mod::AddMod,
       block_user::BlockUserFromCommunity,
       list_community_follower_inboxes,
+      remove_mod::RemoveMod,
       undo_block_user::UndoBlockUserFromCommunity,
+      update::UpdateCommunity,
     },
-    deletion::{
-      delete::DeletePostCommentOrCommunity,
-      undo_delete::UndoDeletePostCommentOrCommunity,
-    },
+    deletion::{delete::Delete, undo_delete::UndoDelete},
     generate_activity_id,
     post::create_or_update::CreateOrUpdatePost,
-    removal::{
-      remove::RemovePostCommentCommunityOrMod,
-      undo_remove::UndoRemovePostCommentOrCommunity,
-    },
+    undo_remove::UndoRemovePostCommentOrCommunity,
     verify_activity,
     verify_community,
     voting::{undo_vote::UndoVote, vote::Vote},
   },
   activity_queue::send_activity_new,
   extensions::context::lemmy_context,
+  fetcher::object_id::ObjectId,
   http::is_activity_already_known,
   insert_activity,
   ActorType,
   CommunityType,
 };
-use activitystreams::activity::kind::AnnounceType;
-use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
+use activitystreams::{
+  activity::kind::AnnounceType,
+  base::AnyBase,
+  primitives::OneOrMany,
+  unparsed::Unparsed,
+};
+use lemmy_apub_lib::{values::PublicUrl, ActivityFields, ActivityHandler};
 use lemmy_db_schema::source::community::Community;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
 #[serde(untagged)]
 pub enum AnnouncableActivities {
   CreateOrUpdateComment(CreateOrUpdateComment),
   CreateOrUpdatePost(Box<CreateOrUpdatePost>),
   Vote(Vote),
   UndoVote(UndoVote),
-  DeletePostCommentOrCommunity(DeletePostCommentOrCommunity),
-  UndoDeletePostCommentOrCommunity(UndoDeletePostCommentOrCommunity),
-  RemovePostCommentCommunityOrMod(RemovePostCommentCommunityOrMod),
+  Delete(Delete),
+  UndoDelete(UndoDelete),
   UndoRemovePostCommentOrCommunity(UndoRemovePostCommentOrCommunity),
+  UpdateCommunity(Box<UpdateCommunity>),
   BlockUserFromCommunity(BlockUserFromCommunity),
   UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
   AddMod(AddMod),
+  RemoveMod(RemoveMod),
 }
 
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
 #[serde(rename_all = "camelCase")]
 pub struct AnnounceActivity {
-  to: PublicUrl,
+  actor: ObjectId<Community>,
+  to: [PublicUrl; 1],
   object: AnnouncableActivities,
   cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: AnnounceType,
+  id: Url,
+  #[serde(rename = "@context")]
+  context: OneOrMany<AnyBase>,
   #[serde(flatten)]
-  common: ActivityCommonFields,
+  unparsed: Unparsed,
 }
 
 impl AnnounceActivity {
@@ -72,27 +79,17 @@ impl AnnounceActivity {
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
     let announce = AnnounceActivity {
-      to: PublicUrl::Public,
+      actor: ObjectId::new(community.actor_id()),
+      to: [PublicUrl::Public],
       object,
       cc: vec![community.followers_url()],
       kind: AnnounceType::Announce,
-      common: ActivityCommonFields {
-        context: lemmy_context(),
-        id: generate_activity_id(&AnnounceType::Announce)?,
-        actor: community.actor_id(),
-        unparsed: Default::default(),
-      },
+      id: generate_activity_id(&AnnounceType::Announce)?,
+      context: lemmy_context(),
+      unparsed: Default::default(),
     };
     let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?;
-    send_activity_new(
-      context,
-      &announce,
-      &announce.common.id,
-      community,
-      inboxes,
-      false,
-    )
-    .await
+    send_activity_new(context, &announce, &announce.id, community, inboxes, false).await
   }
 }
 
@@ -103,22 +100,22 @@ impl ActivityHandler for AnnounceActivity {
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_activity(self.common())?;
-    verify_community(&self.common.actor, context, request_counter).await?;
+    verify_activity(self)?;
+    verify_community(&self.actor, context, request_counter).await?;
     self.object.verify(context, request_counter).await?;
     Ok(())
   }
 
   async fn receive(
-    &self,
+    self,
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    if is_activity_already_known(context.pool(), self.object.common().id_unchecked()).await? {
+    if is_activity_already_known(context.pool(), self.object.id_unchecked()).await? {
       return Ok(());
     }
     insert_activity(
-      self.object.common().id_unchecked(),
+      self.object.id_unchecked(),
       self.object.clone(),
       false,
       true,
@@ -127,8 +124,4 @@ impl ActivityHandler for AnnounceActivity {
     .await?;
     self.object.receive(context, request_counter).await
   }
-
-  fn common(&self) -> &ActivityCommonFields {
-    &self.common
-  }
 }