2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
5 utils::{blocking, get_local_user_view_from_jwt, is_admin},
7 use lemmy_db_schema::source::site::Site;
8 use lemmy_db_views::structs::RegistrationApplicationView;
9 use lemmy_utils::{ConnectionId, LemmyError};
10 use lemmy_websocket::LemmyContext;
12 #[async_trait::async_trait(?Send)]
13 impl Perform for GetUnreadRegistrationApplicationCount {
14 type Response = GetUnreadRegistrationApplicationCountResponse;
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<Self::Response, LemmyError> {
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
25 // Only let admins do this
26 is_admin(&local_user_view)?;
28 let verified_email_only = blocking(context.pool(), Site::read_local_site)
30 .require_email_verification;
32 let registration_applications = blocking(context.pool(), move |conn| {
33 RegistrationApplicationView::get_unread_count(conn, verified_email_only)
38 registration_applications,