2 objects::community::ApubCommunity,
5 block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
8 announce::{AnnounceActivity, RawAnnouncableActivities},
11 update::UpdateCommunity,
14 chat_message::CreateOrUpdateChatMessage,
15 note::CreateOrUpdateNote,
16 page::CreateOrUpdatePage,
18 deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
19 following::{accept::AcceptFollow, follow::Follow, undo_follow::UndoFollow},
20 voting::{undo_vote::UndoVote, vote::Vote},
26 use activitypub_federation::{data::Data, deser::context::WithContext, traits::ActivityHandler};
27 use lemmy_utils::error::LemmyError;
28 use lemmy_websocket::LemmyContext;
29 use serde::{Deserialize, Serialize};
32 #[derive(Debug, Deserialize, Serialize)]
34 #[enum_delegate::implement(ActivityHandler)]
35 pub enum SharedInboxActivities {
36 PersonInboxActivities(Box<WithContext<PersonInboxActivities>>),
37 GroupInboxActivities(Box<WithContext<GroupInboxActivities>>),
40 #[derive(Debug, Deserialize, Serialize)]
42 #[enum_delegate::implement(ActivityHandler)]
43 pub enum GroupInboxActivities {
45 UndoFollow(UndoFollow),
47 // This is a catch-all and needs to be last
48 AnnouncableActivities(RawAnnouncableActivities),
51 #[derive(Clone, Debug, Deserialize, Serialize)]
53 #[enum_delegate::implement(ActivityHandler)]
54 pub enum PersonInboxActivities {
55 AcceptFollow(AcceptFollow),
56 UndoFollow(UndoFollow),
57 CreateOrUpdatePrivateMessage(CreateOrUpdateChatMessage),
59 UndoDelete(UndoDelete),
60 AnnounceActivity(AnnounceActivity),
63 /// This is necessary for user inbox, which can also receive some "announcable" activities,
64 /// eg a comment mention. This needs to be a separate enum so that announcables received in shared
65 /// inbox can fall through to be parsed as GroupInboxActivities::AnnouncableActivities.
66 #[derive(Clone, Debug, Deserialize, Serialize)]
68 #[enum_delegate::implement(ActivityHandler)]
69 pub enum PersonInboxActivitiesWithAnnouncable {
70 PersonInboxActivities(Box<PersonInboxActivities>),
71 AnnouncableActivities(Box<AnnouncableActivities>),
74 #[derive(Clone, Debug, Deserialize, Serialize)]
76 #[enum_delegate::implement(ActivityHandler)]
77 pub enum AnnouncableActivities {
78 CreateOrUpdateComment(CreateOrUpdateNote),
79 CreateOrUpdatePost(CreateOrUpdatePage),
83 UndoDelete(UndoDelete),
84 UpdateCommunity(UpdateCommunity),
86 UndoBlockUser(UndoBlockUser),
89 // For compatibility with Pleroma/Mastodon (send only)
93 #[derive(Clone, Debug, Deserialize, Serialize)]
95 #[enum_delegate::implement(ActivityHandler)]
96 #[allow(clippy::enum_variant_names)]
97 pub enum SiteInboxActivities {
99 UndoBlockUser(UndoBlockUser),
100 DeleteUser(DeleteUser),
103 #[async_trait::async_trait(?Send)]
104 impl InCommunity for AnnouncableActivities {
105 #[tracing::instrument(skip(self, context))]
108 context: &LemmyContext,
109 request_counter: &mut i32,
110 ) -> Result<ApubCommunity, LemmyError> {
111 use AnnouncableActivities::*;
113 CreateOrUpdateComment(a) => a.community(context, request_counter).await,
114 CreateOrUpdatePost(a) => a.community(context, request_counter).await,
115 Vote(a) => a.community(context, request_counter).await,
116 UndoVote(a) => a.community(context, request_counter).await,
117 Delete(a) => a.community(context, request_counter).await,
118 UndoDelete(a) => a.community(context, request_counter).await,
119 UpdateCommunity(a) => a.community(context, request_counter).await,
120 BlockUser(a) => a.community(context, request_counter).await,
121 UndoBlockUser(a) => a.community(context, request_counter).await,
122 AddMod(a) => a.community(context, request_counter).await,
123 RemoveMod(a) => a.community(context, request_counter).await,
124 Page(_) => unimplemented!(),
133 GroupInboxActivities,
134 PersonInboxActivities,
135 PersonInboxActivitiesWithAnnouncable,
138 protocol::tests::test_parse_lemmy_item,
142 fn test_group_inbox() {
143 test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")
145 test_parse_lemmy_item::<GroupInboxActivities>(
146 "assets/lemmy/activities/create_or_update/create_note.json",
152 fn test_person_inbox() {
153 test_parse_lemmy_item::<PersonInboxActivities>("assets/lemmy/activities/following/accept.json")
155 test_parse_lemmy_item::<PersonInboxActivitiesWithAnnouncable>(
156 "assets/lemmy/activities/create_or_update/create_note.json",
159 test_parse_lemmy_item::<PersonInboxActivitiesWithAnnouncable>(
160 "assets/lemmy/activities/create_or_update/create_private_message.json",
166 fn test_site_inbox() {
167 test_parse_lemmy_item::<SiteInboxActivities>(
168 "assets/lemmy/activities/deletion/delete_user.json",