2 activities::generate_activity_id,
3 activity_queue::send_to_community,
4 extensions::context::lemmy_context,
10 kind::{DeleteType, RemoveType, UndoType},
18 use lemmy_api_common::blocking;
19 use lemmy_db_queries::Crud;
20 use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
21 use lemmy_utils::LemmyError;
22 use lemmy_websocket::LemmyContext;
24 #[async_trait::async_trait(?Send)]
25 impl ApubObjectType for Post {
26 async fn send_delete(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
27 let community_id = self.community_id;
28 let community = blocking(context.pool(), move |conn| {
29 Community::read(conn, community_id)
33 let mut delete = Delete::new(
34 creator.actor_id.to_owned().into_inner(),
35 self.ap_id.to_owned().into_inner(),
38 .set_many_contexts(lemmy_context())
39 .set_id(generate_activity_id(DeleteType::Delete)?)
41 .set_many_ccs(vec![community.actor_id()]);
43 send_to_community(delete, creator, &community, None, context).await?;
47 async fn send_undo_delete(
50 context: &LemmyContext,
51 ) -> Result<(), LemmyError> {
52 let community_id = self.community_id;
53 let community = blocking(context.pool(), move |conn| {
54 Community::read(conn, community_id)
58 let mut delete = Delete::new(
59 creator.actor_id.to_owned().into_inner(),
60 self.ap_id.to_owned().into_inner(),
63 .set_many_contexts(lemmy_context())
64 .set_id(generate_activity_id(DeleteType::Delete)?)
66 .set_many_ccs(vec![community.actor_id()]);
68 // Undo that fake activity
69 let mut undo = Undo::new(
70 creator.actor_id.to_owned().into_inner(),
71 delete.into_any_base()?,
74 .set_many_contexts(lemmy_context())
75 .set_id(generate_activity_id(UndoType::Undo)?)
77 .set_many_ccs(vec![community.actor_id()]);
79 send_to_community(undo, creator, &community, None, context).await?;
83 async fn send_remove(&self, mod_: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
84 let community_id = self.community_id;
85 let community = blocking(context.pool(), move |conn| {
86 Community::read(conn, community_id)
90 let mut remove = Remove::new(
91 mod_.actor_id.to_owned().into_inner(),
92 self.ap_id.to_owned().into_inner(),
95 .set_many_contexts(lemmy_context())
96 .set_id(generate_activity_id(RemoveType::Remove)?)
98 .set_many_ccs(vec![community.actor_id()]);
100 send_to_community(remove, mod_, &community, None, context).await?;
104 async fn send_undo_remove(
107 context: &LemmyContext,
108 ) -> Result<(), LemmyError> {
109 let community_id = self.community_id;
110 let community = blocking(context.pool(), move |conn| {
111 Community::read(conn, community_id)
115 let mut remove = Remove::new(
116 mod_.actor_id.to_owned().into_inner(),
117 self.ap_id.to_owned().into_inner(),
120 .set_many_contexts(lemmy_context())
121 .set_id(generate_activity_id(RemoveType::Remove)?)
123 .set_many_ccs(vec![community.actor_id()]);
125 // Undo that fake activity
126 let mut undo = Undo::new(
127 mod_.actor_id.to_owned().into_inner(),
128 remove.into_any_base()?,
131 .set_many_contexts(lemmy_context())
132 .set_id(generate_activity_id(UndoType::Undo)?)
134 .set_many_ccs(vec![community.actor_id()]);
136 send_to_community(undo, mod_, &community, None, context).await?;