2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{GetReportCount, GetReportCountResponse},
6 utils::get_local_user_view_from_jwt,
8 use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
9 use lemmy_utils::{error::LemmyError, ConnectionId};
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetReportCount {
13 type Response = GetReportCountResponse;
15 #[tracing::instrument(skip(context, _websocket_id))]
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<GetReportCountResponse, LemmyError> {
21 let data: &GetReportCount = self;
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
25 let person_id = local_user_view.person.id;
26 let admin = local_user_view.person.admin;
27 let community_id = data.community_id;
30 CommentReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
33 PostReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
35 let private_message_reports = if admin && community_id.is_none() {
36 Some(PrivateMessageReportView::get_report_count(context.pool()).await?)
41 let res = GetReportCountResponse {
45 private_message_reports,