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