2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 comment::{CommentReportResponse, ResolveCommentReport},
6 utils::{get_local_user_view_from_jwt, is_mod_or_admin},
7 websocket::UserOperation,
9 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
10 use lemmy_db_views::structs::CommentReportView;
11 use lemmy_utils::{error::LemmyError, ConnectionId};
13 /// Resolves or unresolves a comment report and notifies the moderators of the community
14 #[async_trait::async_trait(?Send)]
15 impl Perform for ResolveCommentReport {
16 type Response = CommentReportResponse;
18 #[tracing::instrument(skip(context, websocket_id))]
21 context: &Data<LemmyContext>,
22 websocket_id: Option<ConnectionId>,
23 ) -> Result<CommentReportResponse, LemmyError> {
24 let data: &ResolveCommentReport = self;
26 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
28 let report_id = data.report_id;
29 let person_id = local_user_view.person.id;
30 let report = CommentReportView::read(context.pool(), report_id, person_id).await?;
32 let person_id = local_user_view.person.id;
33 is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
36 CommentReport::resolve(context.pool(), report_id, person_id)
38 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
40 CommentReport::unresolve(context.pool(), report_id, person_id)
42 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
45 let report_id = data.report_id;
46 let comment_report_view = CommentReportView::read(context.pool(), report_id, person_id).await?;
48 let res = CommentReportResponse {
52 context.send_mod_ws_message(
53 &UserOperation::ResolveCommentReport,