2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 comment::{CommentReportResponse, ResolveCommentReport},
6 get_local_user_view_from_jwt,
9 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
10 use lemmy_db_views::comment_report_view::CommentReportView;
11 use lemmy_utils::{ConnectionId, LemmyError};
12 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
14 /// Resolves or unresolves a comment report and notifies the moderators of the community
15 #[async_trait::async_trait(?Send)]
16 impl Perform for ResolveCommentReport {
17 type Response = CommentReportResponse;
19 #[tracing::instrument(skip(context, websocket_id))]
22 context: &Data<LemmyContext>,
23 websocket_id: Option<ConnectionId>,
24 ) -> Result<CommentReportResponse, LemmyError> {
25 let data: &ResolveCommentReport = self;
27 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
29 let report_id = data.report_id;
30 let person_id = local_user_view.person.id;
31 let report = blocking(context.pool(), move |conn| {
32 CommentReportView::read(conn, report_id, person_id)
36 let person_id = local_user_view.person.id;
37 is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
39 let resolved = data.resolved;
40 let resolve_fun = move |conn: &'_ _| {
42 CommentReport::resolve(conn, report_id, person_id)
44 CommentReport::unresolve(conn, report_id, person_id)
48 blocking(context.pool(), resolve_fun)
50 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
52 let report_id = data.report_id;
53 let comment_report_view = blocking(context.pool(), move |conn| {
54 CommentReportView::read(conn, report_id, person_id)
58 let res = CommentReportResponse {
62 context.chat_server().do_send(SendModRoomMessage {
63 op: UserOperation::ResolveCommentReport,
64 response: res.clone(),
65 community_id: report.community.id,