2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{PostReportResponse, ResolvePostReport},
5 utils::{get_local_user_view_from_jwt, is_mod_or_admin},
7 use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
8 use lemmy_db_views::structs::PostReportView;
9 use lemmy_utils::{error::LemmyError, ConnectionId};
10 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
12 /// Resolves or unresolves a post report and notifies the moderators of the community
13 #[async_trait::async_trait(?Send)]
14 impl Perform for ResolvePostReport {
15 type Response = PostReportResponse;
17 #[tracing::instrument(skip(context, websocket_id))]
20 context: &Data<LemmyContext>,
21 websocket_id: Option<ConnectionId>,
22 ) -> Result<PostReportResponse, LemmyError> {
23 let data: &ResolvePostReport = self;
25 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
27 let report_id = data.report_id;
28 let person_id = local_user_view.person.id;
29 let report = PostReportView::read(context.pool(), report_id, person_id).await?;
31 let person_id = local_user_view.person.id;
32 is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
35 PostReport::resolve(context.pool(), report_id, person_id)
37 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
39 PostReport::unresolve(context.pool(), report_id, person_id)
41 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
44 let post_report_view = PostReportView::read(context.pool(), report_id, person_id).await?;
46 let res = PostReportResponse { post_report_view };
48 context.chat_server().do_send(SendModRoomMessage {
49 op: UserOperation::ResolvePostReport,
50 response: res.clone(),
51 community_id: report.community.id,