]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activity_lists.rs
Implement instance actor (#1798)
[lemmy.git] / crates / apub / src / activity_lists.rs
index 9fd1a9dc187ae5cdf1b70ccd79459e432e046532..c8666b93a68add90f8f096422e4bc30196e2f41a 100644 (file)
@@ -1,62 +1,59 @@
-use serde::{Deserialize, Serialize};
-
-use lemmy_apub_lib::{
-  traits::{ActivityFields, ActivityHandler, ActorType},
-  verify::verify_urls_match,
-};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-
 use crate::{
   activities::community::announce::GetCommunity,
   objects::community::ApubCommunity,
-  protocol::activities::{
-    community::{
-      add_mod::AddMod,
-      announce::AnnounceActivity,
-      block_user::BlockUserFromCommunity,
-      remove_mod::RemoveMod,
-      report::Report,
-      undo_block_user::UndoBlockUserFromCommunity,
-      update::UpdateCommunity,
-    },
-    create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
-    deletion::{delete::Delete, undo_delete::UndoDelete},
-    following::{
-      accept::AcceptFollowCommunity,
-      follow::FollowCommunity,
-      undo_follow::UndoFollowCommunity,
-    },
-    private_message::{
-      create_or_update::CreateOrUpdatePrivateMessage,
-      delete::DeletePrivateMessage,
-      undo_delete::UndoDeletePrivateMessage,
+  protocol::{
+    activities::{
+      block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
+      community::{
+        add_mod::AddMod,
+        announce::AnnounceActivity,
+        remove_mod::RemoveMod,
+        report::Report,
+        update::UpdateCommunity,
+      },
+      create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
+      deletion::{delete::Delete, undo_delete::UndoDelete},
+      following::{
+        accept::AcceptFollowCommunity,
+        follow::FollowCommunity,
+        undo_follow::UndoFollowCommunity,
+      },
+      private_message::{
+        create_or_update::CreateOrUpdatePrivateMessage,
+        delete::DeletePrivateMessage,
+        undo_delete::UndoDeletePrivateMessage,
+      },
+      voting::{undo_vote::UndoVote, vote::Vote},
     },
-    voting::{undo_vote::UndoVote, vote::Vote},
+    objects::page::Page,
   },
 };
+use lemmy_apub_lib::traits::ActivityHandler;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use serde::{Deserialize, Serialize};
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
 #[serde(untagged)]
 #[activity_handler(LemmyContext)]
 pub enum SharedInboxActivities {
-  GroupInboxActivities(GroupInboxActivities),
+  GroupInboxActivities(Box<GroupInboxActivities>),
   // Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
   // avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
-  PersonInboxActivities(PersonInboxActivities),
+  PersonInboxActivities(Box<PersonInboxActivities>),
 }
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
 #[serde(untagged)]
 #[activity_handler(LemmyContext)]
 pub enum GroupInboxActivities {
   FollowCommunity(FollowCommunity),
   UndoFollowCommunity(UndoFollowCommunity),
-  AnnouncableActivities(AnnouncableActivities),
+  AnnouncableActivities(Box<AnnouncableActivities>),
   Report(Report),
 }
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
 #[serde(untagged)]
 #[activity_handler(LemmyContext)]
 pub enum PersonInboxActivities {
@@ -66,28 +63,39 @@ pub enum PersonInboxActivities {
   CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
   DeletePrivateMessage(DeletePrivateMessage),
   UndoDeletePrivateMessage(UndoDeletePrivateMessage),
-  AnnounceActivity(Box<AnnounceActivity>),
+  AnnounceActivity(AnnounceActivity),
 }
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
 #[serde(untagged)]
 #[activity_handler(LemmyContext)]
 pub enum AnnouncableActivities {
   CreateOrUpdateComment(CreateOrUpdateComment),
-  CreateOrUpdatePost(Box<CreateOrUpdatePost>),
+  CreateOrUpdatePost(CreateOrUpdatePost),
   Vote(Vote),
   UndoVote(UndoVote),
   Delete(Delete),
   UndoDelete(UndoDelete),
-  UpdateCommunity(Box<UpdateCommunity>),
-  BlockUserFromCommunity(BlockUserFromCommunity),
-  UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
+  UpdateCommunity(UpdateCommunity),
+  BlockUser(BlockUser),
+  UndoBlockUser(UndoBlockUser),
   AddMod(AddMod),
   RemoveMod(RemoveMod),
+  // For compatibility with Pleroma/Mastodon (send only)
+  Page(Page),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
+#[serde(untagged)]
+#[activity_handler(LemmyContext)]
+pub enum SiteInboxActivities {
+  BlockUser(BlockUser),
+  UndoBlockUser(UndoBlockUser),
 }
 
 #[async_trait::async_trait(?Send)]
 impl GetCommunity for AnnouncableActivities {
+  #[tracing::instrument(skip(self, context))]
   async fn get_community(
     &self,
     context: &LemmyContext,
@@ -102,12 +110,12 @@ impl GetCommunity for AnnouncableActivities {
       Delete(a) => a.get_community(context, request_counter).await?,
       UndoDelete(a) => a.get_community(context, request_counter).await?,
       UpdateCommunity(a) => a.get_community(context, request_counter).await?,
-      BlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
-      UndoBlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
+      BlockUser(a) => a.get_community(context, request_counter).await?,
+      UndoBlockUser(a) => a.get_community(context, request_counter).await?,
       AddMod(a) => a.get_community(context, request_counter).await?,
       RemoveMod(a) => a.get_community(context, request_counter).await?,
+      Page(_) => unimplemented!(),
     };
-    verify_urls_match(self.actor(), &community.actor_id())?;
     Ok(community)
   }
 }