1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{PostResponse, RemovePost},
5 utils::{blocking, check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
7 use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
11 moderator::{ModRemovePost, ModRemovePostForm},
16 use lemmy_utils::{ConnectionId, LemmyError};
17 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
19 #[async_trait::async_trait(?Send)]
20 impl PerformCrud for RemovePost {
21 type Response = PostResponse;
23 #[tracing::instrument(skip(context, websocket_id))]
26 context: &Data<LemmyContext>,
27 websocket_id: Option<ConnectionId>,
28 ) -> Result<PostResponse, LemmyError> {
29 let data: &RemovePost = self;
31 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
33 let post_id = data.post_id;
34 let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
37 local_user_view.person.id,
38 orig_post.community_id,
43 // Verify that only the mods can remove
46 local_user_view.person.id,
47 orig_post.community_id,
52 let post_id = data.post_id;
53 let removed = data.removed;
54 let updated_post = blocking(context.pool(), move |conn| {
55 Post::update_removed(conn, post_id, removed)
60 let form = ModRemovePostForm {
61 mod_person_id: local_user_view.person.id,
62 post_id: data.post_id,
63 removed: Some(removed),
64 reason: data.reason.to_owned(),
66 blocking(context.pool(), move |conn| {
67 ModRemovePost::create(conn, &form)
71 let res = send_post_ws_message(
73 UserOperationCrud::RemovePost,
75 Some(local_user_view.person.id),
81 let community = blocking(context.pool(), move |conn| {
82 Community::read(conn, orig_post.community_id)
85 let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
86 send_apub_delete_in_community(
87 local_user_view.person,
90 data.reason.clone().or_else(|| Some("".to_string())),