2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{GetReportCount, GetReportCountResponse},
6 utils::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;
22 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
24 let person_id = local_user_view.person.id;
25 let admin = local_user_view.person.admin;
26 let community_id = data.community_id;
29 CommentReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
32 PostReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
34 let private_message_reports = if admin && community_id.is_none() {
35 Some(PrivateMessageReportView::get_report_count(context.pool()).await?)
40 let res = GetReportCountResponse {
44 private_message_reports,