2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
5 utils::{get_local_user_view_from_jwt, is_admin},
9 source::private_message_report::PrivateMessageReport,
12 use lemmy_db_views::structs::PrivateMessageReportView;
13 use lemmy_utils::{error::LemmyError, ConnectionId};
14 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
16 #[async_trait::async_trait(?Send)]
17 impl Perform for ResolvePrivateMessageReport {
18 type Response = PrivateMessageReportResponse;
20 #[tracing::instrument(skip(context, websocket_id))]
23 context: &Data<LemmyContext>,
24 websocket_id: Option<ConnectionId>,
25 ) -> Result<Self::Response, LemmyError> {
27 get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).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.chat_server().do_send(SendModRoomMessage {
51 op: UserOperation::ResolvePrivateMessageReport,
52 response: res.clone(),
53 community_id: CommunityId(0),