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::{comment::Comment, 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 Comment {
26 async fn send_delete(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
27 let post_id = self.post_id;
28 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
30 let community_id = post.community_id;
31 let community = blocking(context.pool(), move |conn| {
32 Community::read(conn, community_id)
36 let mut delete = Delete::new(
37 creator.actor_id.to_owned().into_inner(),
38 self.ap_id.to_owned().into_inner(),
41 .set_many_contexts(lemmy_context())
42 .set_id(generate_activity_id(DeleteType::Delete)?)
44 .set_many_ccs(vec![community.actor_id()]);
46 send_to_community(delete, creator, &community, None, context).await?;
50 async fn send_undo_delete(
53 context: &LemmyContext,
54 ) -> Result<(), LemmyError> {
55 let post_id = self.post_id;
56 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
58 let community_id = post.community_id;
59 let community = blocking(context.pool(), move |conn| {
60 Community::read(conn, community_id)
64 // Generate a fake delete activity, with the correct object
65 let mut delete = Delete::new(
66 creator.actor_id.to_owned().into_inner(),
67 self.ap_id.to_owned().into_inner(),
70 .set_many_contexts(lemmy_context())
71 .set_id(generate_activity_id(DeleteType::Delete)?)
73 .set_many_ccs(vec![community.actor_id()]);
75 // Undo that fake activity
76 let mut undo = Undo::new(
77 creator.actor_id.to_owned().into_inner(),
78 delete.into_any_base()?,
81 .set_many_contexts(lemmy_context())
82 .set_id(generate_activity_id(UndoType::Undo)?)
84 .set_many_ccs(vec![community.actor_id()]);
86 send_to_community(undo, creator, &community, None, context).await?;
90 async fn send_remove(&self, mod_: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
91 let post_id = self.post_id;
92 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
94 let community_id = post.community_id;
95 let community = blocking(context.pool(), move |conn| {
96 Community::read(conn, community_id)
100 let mut remove = Remove::new(
101 mod_.actor_id.to_owned().into_inner(),
102 self.ap_id.to_owned().into_inner(),
105 .set_many_contexts(lemmy_context())
106 .set_id(generate_activity_id(RemoveType::Remove)?)
108 .set_many_ccs(vec![community.actor_id()]);
110 send_to_community(remove, mod_, &community, None, context).await?;
114 async fn send_undo_remove(
117 context: &LemmyContext,
118 ) -> Result<(), LemmyError> {
119 let post_id = self.post_id;
120 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
122 let community_id = post.community_id;
123 let community = blocking(context.pool(), move |conn| {
124 Community::read(conn, community_id)
128 // Generate a fake delete activity, with the correct object
129 let mut remove = Remove::new(
130 mod_.actor_id.to_owned().into_inner(),
131 self.ap_id.to_owned().into_inner(),
134 .set_many_contexts(lemmy_context())
135 .set_id(generate_activity_id(RemoveType::Remove)?)
137 .set_many_ccs(vec![community.actor_id()]);
139 // Undo that fake activity
140 let mut undo = Undo::new(
141 mod_.actor_id.to_owned().into_inner(),
142 remove.into_any_base()?,
145 .set_many_contexts(lemmy_context())
146 .set_id(generate_activity_id(UndoType::Undo)?)
148 .set_many_ccs(vec![community.actor_id()]);
150 send_to_community(undo, mod_, &community, None, context).await?;