2023-09-05 09:33:46 +00:00
|
|
|
use actix_web::web::{Data, Json};
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-04-13 18:12:25 +00:00
|
|
|
person::{GetReportCount, GetReportCountResponse},
|
2023-10-13 13:48:18 +00:00
|
|
|
utils::check_community_mod_action_opt,
|
2022-04-13 18:12:25 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::structs::{
|
|
|
|
CommentReportView,
|
|
|
|
LocalUserView,
|
|
|
|
PostReportView,
|
|
|
|
PrivateMessageReportView,
|
|
|
|
};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn report_count(
|
|
|
|
data: Json<GetReportCount>,
|
|
|
|
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<GetReportCountResponse>, LemmyError> {
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
let admin = local_user_view.local_user.admin;
|
|
|
|
let community_id = data.community_id;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-10-13 13:48:18 +00:00
|
|
|
check_community_mod_action_opt(&local_user_view, community_id, &mut context.pool()).await?;
|
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let comment_reports =
|
|
|
|
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let post_reports =
|
|
|
|
PostReportView::get_report_count(&mut context.pool(), person_id, admin, community_id).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let private_message_reports = if admin && community_id.is_none() {
|
|
|
|
Some(PrivateMessageReportView::get_report_count(&mut context.pool()).await?)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
Ok(Json(GetReportCountResponse {
|
|
|
|
community_id,
|
|
|
|
comment_reports,
|
|
|
|
post_reports,
|
|
|
|
private_message_reports,
|
|
|
|
}))
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|