]> Untitled Git - lemmy.git/blob - crates/apub/src/activity_lists.rs
Migrate towards using page.attachment field for url (ref #2144) (#2182)
[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, 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 pub enum SiteInboxActivities {
91   BlockUser(BlockUser),
92   UndoBlockUser(UndoBlockUser),
93 }
94
95 #[async_trait::async_trait(?Send)]
96 impl GetCommunity for AnnouncableActivities {
97   #[tracing::instrument(skip(self, context))]
98   async fn get_community(
99     &self,
100     context: &LemmyContext,
101     request_counter: &mut i32,
102   ) -> Result<ApubCommunity, LemmyError> {
103     use AnnouncableActivities::*;
104     let community = match self {
105       CreateOrUpdateComment(a) => a.get_community(context, request_counter).await?,
106       CreateOrUpdatePost(a) => a.get_community(context, request_counter).await?,
107       Vote(a) => a.get_community(context, request_counter).await?,
108       UndoVote(a) => a.get_community(context, request_counter).await?,
109       Delete(a) => a.get_community(context, request_counter).await?,
110       UndoDelete(a) => a.get_community(context, request_counter).await?,
111       UpdateCommunity(a) => a.get_community(context, request_counter).await?,
112       BlockUser(a) => a.get_community(context, request_counter).await?,
113       UndoBlockUser(a) => a.get_community(context, request_counter).await?,
114       AddMod(a) => a.get_community(context, request_counter).await?,
115       RemoveMod(a) => a.get_community(context, request_counter).await?,
116       Page(_) => unimplemented!(),
117     };
118     Ok(community)
119   }
120 }