3 comment::create_or_update::CreateOrUpdateComment,
6 block_user::BlockUserFromCommunity,
7 list_community_follower_inboxes,
8 undo_block_user::UndoBlockUserFromCommunity,
11 delete::DeletePostCommentOrCommunity,
12 undo_delete::UndoDeletePostCommentOrCommunity,
15 post::create_or_update::CreateOrUpdatePost,
17 remove::RemovePostCommentCommunityOrMod,
18 undo_remove::UndoRemovePostCommentOrCommunity,
22 voting::{undo_vote::UndoVote, vote::Vote},
24 activity_queue::send_activity_new,
25 extensions::context::lemmy_context,
26 http::is_activity_already_known,
31 use activitystreams::activity::kind::AnnounceType;
32 use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
33 use lemmy_db_schema::source::community::Community;
34 use lemmy_utils::LemmyError;
35 use lemmy_websocket::LemmyContext;
36 use serde::{Deserialize, Serialize};
39 #[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)]
41 pub enum AnnouncableActivities {
42 CreateOrUpdateComment(CreateOrUpdateComment),
43 CreateOrUpdatePost(Box<CreateOrUpdatePost>),
46 DeletePostCommentOrCommunity(DeletePostCommentOrCommunity),
47 UndoDeletePostCommentOrCommunity(UndoDeletePostCommentOrCommunity),
48 RemovePostCommentCommunityOrMod(RemovePostCommentCommunityOrMod),
49 UndoRemovePostCommentOrCommunity(UndoRemovePostCommentOrCommunity),
50 BlockUserFromCommunity(BlockUserFromCommunity),
51 UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
55 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
56 #[serde(rename_all = "camelCase")]
57 pub struct AnnounceActivity {
59 object: AnnouncableActivities,
61 #[serde(rename = "type")]
64 common: ActivityCommonFields,
67 impl AnnounceActivity {
69 object: AnnouncableActivities,
70 community: &Community,
71 additional_inboxes: Vec<Url>,
72 context: &LemmyContext,
73 ) -> Result<(), LemmyError> {
74 let announce = AnnounceActivity {
75 to: PublicUrl::Public,
77 cc: vec![community.followers_url()],
78 kind: AnnounceType::Announce,
79 common: ActivityCommonFields {
80 context: lemmy_context(),
81 id: generate_activity_id(&AnnounceType::Announce)?,
82 actor: community.actor_id(),
83 unparsed: Default::default(),
86 let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?;
99 #[async_trait::async_trait(?Send)]
100 impl ActivityHandler for AnnounceActivity {
103 context: &LemmyContext,
104 request_counter: &mut i32,
105 ) -> Result<(), LemmyError> {
106 verify_activity(self.common())?;
107 verify_community(&self.common.actor, context, request_counter).await?;
108 self.object.verify(context, request_counter).await?;
114 context: &LemmyContext,
115 request_counter: &mut i32,
116 ) -> Result<(), LemmyError> {
117 if is_activity_already_known(context.pool(), self.object.common().id_unchecked()).await? {
121 self.object.common().id_unchecked(),
128 self.object.receive(context, request_counter).await
131 fn common(&self) -> &ActivityCommonFields {