1 use serde::{Deserialize, Serialize};
4 traits::{ActivityFields, ActivityHandler, ActorType},
5 verify::verify_urls_match,
7 use lemmy_utils::LemmyError;
8 use lemmy_websocket::LemmyContext;
11 activities::community::announce::GetCommunity,
12 objects::community::ApubCommunity,
13 protocol::activities::{
16 announce::AnnounceActivity,
17 block_user::BlockUserFromCommunity,
18 remove_mod::RemoveMod,
20 undo_block_user::UndoBlockUserFromCommunity,
21 update::UpdateCommunity,
23 create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
24 deletion::{delete::Delete, undo_delete::UndoDelete},
26 accept::AcceptFollowCommunity,
27 follow::FollowCommunity,
28 undo_follow::UndoFollowCommunity,
31 create_or_update::CreateOrUpdatePrivateMessage,
32 delete::DeletePrivateMessage,
33 undo_delete::UndoDeletePrivateMessage,
35 voting::{undo_vote::UndoVote, vote::Vote},
39 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
41 #[activity_handler(LemmyContext)]
42 pub enum SharedInboxActivities {
43 GroupInboxActivities(GroupInboxActivities),
44 // Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
45 // avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
46 PersonInboxActivities(PersonInboxActivities),
49 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
51 #[activity_handler(LemmyContext)]
52 pub enum GroupInboxActivities {
53 FollowCommunity(FollowCommunity),
54 UndoFollowCommunity(UndoFollowCommunity),
55 AnnouncableActivities(AnnouncableActivities),
59 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
61 #[activity_handler(LemmyContext)]
62 pub enum PersonInboxActivities {
63 AcceptFollowCommunity(AcceptFollowCommunity),
64 /// Some activities can also be sent from user to user, eg a comment with mentions
65 AnnouncableActivities(AnnouncableActivities),
66 CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
67 DeletePrivateMessage(DeletePrivateMessage),
68 UndoDeletePrivateMessage(UndoDeletePrivateMessage),
69 AnnounceActivity(Box<AnnounceActivity>),
72 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
74 #[activity_handler(LemmyContext)]
75 pub enum AnnouncableActivities {
76 CreateOrUpdateComment(CreateOrUpdateComment),
77 CreateOrUpdatePost(Box<CreateOrUpdatePost>),
81 UndoDelete(UndoDelete),
82 UpdateCommunity(Box<UpdateCommunity>),
83 BlockUserFromCommunity(BlockUserFromCommunity),
84 UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
89 #[async_trait::async_trait(?Send)]
90 impl GetCommunity for AnnouncableActivities {
91 async fn get_community(
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?,
110 verify_urls_match(self.actor(), &community.actor_id())?;