2 activities::generate_activity_id,
3 activity_queue::send_to_community,
4 extensions::context::lemmy_context,
11 kind::{DeleteType, DislikeType, LikeType, RemoveType, UndoType},
21 use lemmy_api_common::blocking;
22 use lemmy_db_queries::Crud;
23 use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
24 use lemmy_utils::LemmyError;
25 use lemmy_websocket::LemmyContext;
27 #[async_trait::async_trait(?Send)]
28 impl ApubObjectType for Post {
32 _context: &LemmyContext,
33 ) -> Result<(), LemmyError> {
40 _context: &LemmyContext,
41 ) -> Result<(), LemmyError> {
45 async fn send_delete(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
46 let community_id = self.community_id;
47 let community = blocking(context.pool(), move |conn| {
48 Community::read(conn, community_id)
52 let mut delete = Delete::new(
53 creator.actor_id.to_owned().into_inner(),
54 self.ap_id.to_owned().into_inner(),
57 .set_many_contexts(lemmy_context())
58 .set_id(generate_activity_id(DeleteType::Delete)?)
60 .set_many_ccs(vec![community.actor_id()]);
62 send_to_community(delete, creator, &community, None, context).await?;
66 async fn send_undo_delete(
69 context: &LemmyContext,
70 ) -> Result<(), LemmyError> {
71 let community_id = self.community_id;
72 let community = blocking(context.pool(), move |conn| {
73 Community::read(conn, community_id)
77 let mut delete = Delete::new(
78 creator.actor_id.to_owned().into_inner(),
79 self.ap_id.to_owned().into_inner(),
82 .set_many_contexts(lemmy_context())
83 .set_id(generate_activity_id(DeleteType::Delete)?)
85 .set_many_ccs(vec![community.actor_id()]);
87 // Undo that fake activity
88 let mut undo = Undo::new(
89 creator.actor_id.to_owned().into_inner(),
90 delete.into_any_base()?,
93 .set_many_contexts(lemmy_context())
94 .set_id(generate_activity_id(UndoType::Undo)?)
96 .set_many_ccs(vec![community.actor_id()]);
98 send_to_community(undo, creator, &community, None, context).await?;
102 async fn send_remove(&self, mod_: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
103 let community_id = self.community_id;
104 let community = blocking(context.pool(), move |conn| {
105 Community::read(conn, community_id)
109 let mut remove = Remove::new(
110 mod_.actor_id.to_owned().into_inner(),
111 self.ap_id.to_owned().into_inner(),
114 .set_many_contexts(lemmy_context())
115 .set_id(generate_activity_id(RemoveType::Remove)?)
117 .set_many_ccs(vec![community.actor_id()]);
119 send_to_community(remove, mod_, &community, None, context).await?;
123 async fn send_undo_remove(
126 context: &LemmyContext,
127 ) -> Result<(), LemmyError> {
128 let community_id = self.community_id;
129 let community = blocking(context.pool(), move |conn| {
130 Community::read(conn, community_id)
134 let mut remove = Remove::new(
135 mod_.actor_id.to_owned().into_inner(),
136 self.ap_id.to_owned().into_inner(),
139 .set_many_contexts(lemmy_context())
140 .set_id(generate_activity_id(RemoveType::Remove)?)
142 .set_many_ccs(vec![community.actor_id()]);
144 // Undo that fake activity
145 let mut undo = Undo::new(
146 mod_.actor_id.to_owned().into_inner(),
147 remove.into_any_base()?,
150 .set_many_contexts(lemmy_context())
151 .set_id(generate_activity_id(UndoType::Undo)?)
153 .set_many_ccs(vec![community.actor_id()]);
155 send_to_community(undo, mod_, &community, None, context).await?;
160 #[async_trait::async_trait(?Send)]
161 impl ApubLikeableType for Post {
162 async fn send_like(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
163 let community_id = self.community_id;
164 let community = blocking(context.pool(), move |conn| {
165 Community::read(conn, community_id)
169 let mut like = Like::new(
170 creator.actor_id.to_owned().into_inner(),
171 self.ap_id.to_owned().into_inner(),
174 .set_many_contexts(lemmy_context())
175 .set_id(generate_activity_id(LikeType::Like)?)
177 .set_many_ccs(vec![community.actor_id()]);
179 send_to_community(like, creator, &community, None, context).await?;
183 async fn send_dislike(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
184 let community_id = self.community_id;
185 let community = blocking(context.pool(), move |conn| {
186 Community::read(conn, community_id)
190 let mut dislike = Dislike::new(
191 creator.actor_id.to_owned().into_inner(),
192 self.ap_id.to_owned().into_inner(),
195 .set_many_contexts(lemmy_context())
196 .set_id(generate_activity_id(DislikeType::Dislike)?)
198 .set_many_ccs(vec![community.actor_id()]);
200 send_to_community(dislike, creator, &community, None, context).await?;
204 async fn send_undo_like(
207 context: &LemmyContext,
208 ) -> Result<(), LemmyError> {
209 let community_id = self.community_id;
210 let community = blocking(context.pool(), move |conn| {
211 Community::read(conn, community_id)
215 let mut like = Like::new(
216 creator.actor_id.to_owned().into_inner(),
217 self.ap_id.to_owned().into_inner(),
220 .set_many_contexts(lemmy_context())
221 .set_id(generate_activity_id(LikeType::Like)?)
223 .set_many_ccs(vec![community.actor_id()]);
225 // Undo that fake activity
226 let mut undo = Undo::new(
227 creator.actor_id.to_owned().into_inner(),
228 like.into_any_base()?,
231 .set_many_contexts(lemmy_context())
232 .set_id(generate_activity_id(UndoType::Undo)?)
234 .set_many_ccs(vec![community.actor_id()]);
236 send_to_community(undo, creator, &community, None, context).await?;