]> Untitled Git - lemmy.git/blob - crates/apub/src/activity_lists.rs
Federate user account deletion (fixes #1284) (#2199)
[lemmy.git] / crates / apub / src / activity_lists.rs
1 use crate::{
2   activities::community::announce::GetCommunity,
3   objects::community::ApubCommunity,
4   protocol::{
5     activities::{
6       block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
7       community::{
8         add_mod::AddMod,
9         announce::AnnounceActivity,
10         remove_mod::RemoveMod,
11         report::Report,
12         update::UpdateCommunity,
13       },
14       create_or_update::{
15         comment::CreateOrUpdateComment,
16         post::CreateOrUpdatePost,
17         private_message::CreateOrUpdatePrivateMessage,
18       },
19       deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
20       following::{
21         accept::AcceptFollowCommunity,
22         follow::FollowCommunity,
23         undo_follow::UndoFollowCommunity,
24       },
25       voting::{undo_vote::UndoVote, vote::Vote},
26     },
27     objects::page::Page,
28   },
29 };
30 use lemmy_apub_lib::traits::ActivityHandler;
31 use lemmy_utils::LemmyError;
32 use lemmy_websocket::LemmyContext;
33 use serde::{Deserialize, Serialize};
34
35 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
36 #[serde(untagged)]
37 #[activity_handler(LemmyContext)]
38 pub enum SharedInboxActivities {
39   GroupInboxActivities(Box<GroupInboxActivities>),
40   // Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
41   // avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
42   PersonInboxActivities(Box<PersonInboxActivities>),
43 }
44
45 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
46 #[serde(untagged)]
47 #[activity_handler(LemmyContext)]
48 pub enum GroupInboxActivities {
49   FollowCommunity(FollowCommunity),
50   UndoFollowCommunity(UndoFollowCommunity),
51   AnnouncableActivities(Box<AnnouncableActivities>),
52   Report(Report),
53 }
54
55 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
56 #[serde(untagged)]
57 #[activity_handler(LemmyContext)]
58 pub enum PersonInboxActivities {
59   AcceptFollowCommunity(AcceptFollowCommunity),
60   /// Some activities can also be sent from user to user, eg a comment with mentions
61   AnnouncableActivities(AnnouncableActivities),
62   CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
63   Delete(Delete),
64   UndoDelete(UndoDelete),
65   AnnounceActivity(AnnounceActivity),
66 }
67
68 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
69 #[serde(untagged)]
70 #[activity_handler(LemmyContext)]
71 pub enum AnnouncableActivities {
72   CreateOrUpdateComment(CreateOrUpdateComment),
73   CreateOrUpdatePost(Box<CreateOrUpdatePost>),
74   Vote(Vote),
75   UndoVote(UndoVote),
76   Delete(Delete),
77   UndoDelete(UndoDelete),
78   UpdateCommunity(UpdateCommunity),
79   BlockUser(BlockUser),
80   UndoBlockUser(UndoBlockUser),
81   AddMod(AddMod),
82   RemoveMod(RemoveMod),
83   // For compatibility with Pleroma/Mastodon (send only)
84   Page(Page),
85 }
86
87 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
88 #[serde(untagged)]
89 #[activity_handler(LemmyContext)]
90 #[allow(clippy::enum_variant_names)]
91 pub enum SiteInboxActivities {
92   BlockUser(BlockUser),
93   UndoBlockUser(UndoBlockUser),
94   DeleteUser(DeleteUser),
95 }
96
97 #[async_trait::async_trait(?Send)]
98 impl GetCommunity for AnnouncableActivities {
99   #[tracing::instrument(skip(self, context))]
100   async fn get_community(
101     &self,
102     context: &LemmyContext,
103     request_counter: &mut i32,
104   ) -> Result<ApubCommunity, LemmyError> {
105     use AnnouncableActivities::*;
106     let community = match self {
107       CreateOrUpdateComment(a) => a.get_community(context, request_counter).await?,
108       CreateOrUpdatePost(a) => a.get_community(context, request_counter).await?,
109       Vote(a) => a.get_community(context, request_counter).await?,
110       UndoVote(a) => a.get_community(context, request_counter).await?,
111       Delete(a) => a.get_community(context, request_counter).await?,
112       UndoDelete(a) => a.get_community(context, request_counter).await?,
113       UpdateCommunity(a) => a.get_community(context, request_counter).await?,
114       BlockUser(a) => a.get_community(context, request_counter).await?,
115       UndoBlockUser(a) => a.get_community(context, request_counter).await?,
116       AddMod(a) => a.get_community(context, request_counter).await?,
117       RemoveMod(a) => a.get_community(context, request_counter).await?,
118       Page(_) => unimplemented!(),
119     };
120     Ok(community)
121   }
122 }