2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 site::{PurgeComment, PurgeItemResponse},
5 utils::{get_local_user_view_from_jwt, is_admin},
10 moderator::{AdminPurgeComment, AdminPurgeCommentForm},
14 use lemmy_utils::{error::LemmyError, ConnectionId};
15 use lemmy_websocket::LemmyContext;
17 #[async_trait::async_trait(?Send)]
18 impl Perform for PurgeComment {
19 type Response = PurgeItemResponse;
21 #[tracing::instrument(skip(context, _websocket_id))]
24 context: &Data<LemmyContext>,
25 _websocket_id: Option<ConnectionId>,
26 ) -> Result<Self::Response, LemmyError> {
27 let data: &Self = self;
29 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
31 // Only let admins purge an item
32 is_admin(&local_user_view)?;
34 let comment_id = data.comment_id;
36 // Read the comment to get the post_id
37 let comment = Comment::read(context.pool(), comment_id).await?;
39 let post_id = comment.post_id;
41 // TODO read comments for pictrs images and purge them
43 Comment::delete(context.pool(), comment_id).await?;
46 let reason = data.reason.clone();
47 let form = AdminPurgeCommentForm {
48 admin_person_id: local_user_view.person.id,
53 AdminPurgeComment::create(context.pool(), &form).await?;
55 Ok(PurgeItemResponse { success: true })