2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
6 utils::{is_admin, local_user_view_from_jwt},
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> {
27 let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
29 is_admin(&local_user_view)?;
31 let report_id = self.report_id;
32 let person_id = local_user_view.person.id;
34 PrivateMessageReport::resolve(context.pool(), report_id, person_id)
36 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
38 PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
40 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
43 let private_message_report_view =
44 PrivateMessageReportView::read(context.pool(), report_id).await?;
46 let res = PrivateMessageReportResponse {
47 private_message_report_view,
50 context.send_mod_ws_message(
51 &UserOperation::ResolvePrivateMessageReport,