2023-09-05 09:33:46 +00:00
|
|
|
use actix_web::web::{Data, Json};
|
2022-09-19 22:58:42 +00:00
|
|
|
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-09-21 10:42:28 +00:00
|
|
|
utils::is_admin,
|
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};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView};
|
2023-07-10 14:50:07 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
2022-09-19 22:58:42 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn resolve_pm_report(
|
|
|
|
data: Json<ResolvePrivateMessageReport>,
|
|
|
|
context: Data<LemmyContext>,
|
2023-09-21 10:42:28 +00:00
|
|
|
local_user_view: LocalUserView,
|
2023-09-05 09:33:46 +00:00
|
|
|
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> {
|
|
|
|
is_admin(&local_user_view)?;
|
2022-09-19 22:58:42 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let report_id = data.report_id;
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
if data.resolved {
|
|
|
|
PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
|
|
|
} else {
|
|
|
|
PrivateMessageReport::unresolve(&mut context.pool(), report_id, person_id)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
|
|
|
}
|
2022-11-09 10:05:00 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let private_message_report_view =
|
|
|
|
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
Ok(Json(PrivateMessageReportResponse {
|
|
|
|
private_message_report_view,
|
|
|
|
}))
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|