1 use activitypub_federation::config::Data;
2 use actix_web::web::Json;
3 use lemmy_api_common::{
4 build_response::build_post_response,
6 post::{PostResponse, RemovePost},
7 send_activity::{ActivityChannel, SendActivityData},
8 utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
10 use lemmy_db_schema::{
12 moderator::{ModRemovePost, ModRemovePostForm},
13 post::{Post, PostUpdateForm},
17 use lemmy_utils::error::LemmyError;
19 #[tracing::instrument(skip(context))]
20 pub async fn remove_post(
21 data: Json<RemovePost>,
22 context: Data<LemmyContext>,
23 ) -> Result<Json<PostResponse>, LemmyError> {
24 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
26 let post_id = data.post_id;
27 let orig_post = Post::read(&mut context.pool(), post_id).await?;
30 local_user_view.person.id,
31 orig_post.community_id,
36 // Verify that only the mods can remove
39 local_user_view.person.id,
40 orig_post.community_id,
45 let post_id = data.post_id;
46 let removed = data.removed;
47 let post = Post::update(
50 &PostUpdateForm::builder().removed(Some(removed)).build(),
55 let form = ModRemovePostForm {
56 mod_person_id: local_user_view.person.id,
57 post_id: data.post_id,
58 removed: Some(removed),
59 reason: data.reason.clone(),
61 ModRemovePost::create(&mut context.pool(), &form).await?;
63 let person_id = local_user_view.person.id;
64 ActivityChannel::submit_activity(
65 SendActivityData::RemovePost(post, local_user_view.person, data.0),
70 build_post_response(&context, orig_post.community_id, person_id, post_id).await