2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
6 utils::{get_local_user_view_from_jwt, is_admin},
7 websocket::UserOperation,
10 newtypes::CommunityId,
11 source::private_message_report::PrivateMessageReport,
14 use lemmy_db_views::structs::PrivateMessageReportView;
15 use lemmy_utils::{error::LemmyError, ConnectionId};
17 #[async_trait::async_trait(?Send)]
18 impl Perform for ResolvePrivateMessageReport {
19 type Response = PrivateMessageReportResponse;
21 #[tracing::instrument(skip(context, websocket_id))]
24 context: &Data<LemmyContext>,
25 websocket_id: Option<ConnectionId>,
26 ) -> Result<Self::Response, LemmyError> {
28 get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
30 is_admin(&local_user_view)?;
32 let report_id = self.report_id;
33 let person_id = local_user_view.person.id;
35 PrivateMessageReport::resolve(context.pool(), report_id, person_id)
37 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
39 PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
41 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
44 let private_message_report_view =
45 PrivateMessageReportView::read(context.pool(), report_id).await?;
47 let res = PrivateMessageReportResponse {
48 private_message_report_view,
51 context.send_mod_ws_message(
52 &UserOperation::ResolvePrivateMessageReport,