2022-09-19 22:58:42 +00:00
|
|
|
use crate::Perform;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-09-19 22:58:42 +00:00
|
|
|
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::{is_admin, local_user_view_from_jwt},
|
2022-09-19 22:58:42 +00:00
|
|
|
};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
|
2022-09-19 22:58:42 +00:00
|
|
|
use lemmy_db_views::structs::PrivateMessageReportView;
|
2023-07-10 14:50:07 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
2022-09-19 22:58:42 +00:00
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl Perform for ResolvePrivateMessageReport {
|
|
|
|
type Response = PrivateMessageReportResponse;
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
|
|
|
|
is_admin(&local_user_view)?;
|
|
|
|
|
|
|
|
let report_id = self.report_id;
|
|
|
|
let person_id = local_user_view.person.id;
|
2022-11-09 10:05:00 +00:00
|
|
|
if self.resolved {
|
2023-07-11 13:09:59 +00:00
|
|
|
PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2023-07-10 14:50:07 +00:00
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
2022-11-09 10:05:00 +00:00
|
|
|
} else {
|
2023-07-11 13:09:59 +00:00
|
|
|
PrivateMessageReport::unresolve(&mut context.pool(), report_id, person_id)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2023-07-10 14:50:07 +00:00
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
2022-11-09 10:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let private_message_report_view =
|
2023-07-11 13:09:59 +00:00
|
|
|
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
Ok(PrivateMessageReportResponse {
|
2022-09-19 22:58:42 +00:00
|
|
|
private_message_report_view,
|
2023-06-06 16:27:22 +00:00
|
|
|
})
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|
|
|
|
}
|