2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 comment::{CommentReportResponse, ResolveCommentReport},
5 utils::{blocking, get_local_user_view_from_jwt, is_mod_or_admin},
7 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
8 use lemmy_db_views::structs::CommentReportView;
9 use lemmy_utils::{ConnectionId, LemmyError};
10 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
12 /// Resolves or unresolves a comment report and notifies the moderators of the community
13 #[async_trait::async_trait(?Send)]
14 impl Perform for ResolveCommentReport {
15 type Response = CommentReportResponse;
17 #[tracing::instrument(skip(context, websocket_id))]
20 context: &Data<LemmyContext>,
21 websocket_id: Option<ConnectionId>,
22 ) -> Result<CommentReportResponse, LemmyError> {
23 let data: &ResolveCommentReport = 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 = blocking(context.pool(), move |conn| {
30 CommentReportView::read(conn, report_id, person_id)
34 let person_id = local_user_view.person.id;
35 is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
37 let resolved = data.resolved;
38 let resolve_fun = move |conn: &'_ _| {
40 CommentReport::resolve(conn, report_id, person_id)
42 CommentReport::unresolve(conn, report_id, person_id)
46 blocking(context.pool(), resolve_fun)
48 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
50 let report_id = data.report_id;
51 let comment_report_view = blocking(context.pool(), move |conn| {
52 CommentReportView::read(conn, report_id, person_id)
56 let res = CommentReportResponse {
60 context.chat_server().do_send(SendModRoomMessage {
61 op: UserOperation::ResolveCommentReport,
62 response: res.clone(),
63 community_id: report.community.id,