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