2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 site::{PurgeComment, PurgeItemResponse},
6 utils::{is_admin, local_user_view_from_jwt},
11 moderator::{AdminPurgeComment, AdminPurgeCommentForm},
15 use lemmy_utils::error::LemmyError;
17 #[async_trait::async_trait(?Send)]
18 impl Perform for PurgeComment {
19 type Response = PurgeItemResponse;
21 #[tracing::instrument(skip(context))]
22 async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
23 let data: &Self = self;
24 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
26 // Only let admin purge an item
27 is_admin(&local_user_view)?;
29 let comment_id = data.comment_id;
31 // Read the comment to get the post_id
32 let comment = Comment::read(&mut context.pool(), comment_id).await?;
34 let post_id = comment.post_id;
36 // TODO read comments for pictrs images and purge them
38 Comment::delete(&mut context.pool(), comment_id).await?;
41 let reason = data.reason.clone();
42 let form = AdminPurgeCommentForm {
43 admin_person_id: local_user_view.person.id,
48 AdminPurgeComment::create(&mut context.pool(), &form).await?;
50 Ok(PurgeItemResponse { success: true })