diff --git a/src/api/client_server/unversioned.rs b/src/api/client_server/unversioned.rs index c3c6d9e1..69a477a6 100644 --- a/src/api/client_server/unversioned.rs +++ b/src/api/client_server/unversioned.rs @@ -155,7 +155,20 @@ pub(crate) async fn syncv3_client_server_json() -> Result { /// `/_matrix/federation/v1/version` pub(crate) async fn conduwuit_server_version() -> Result { Ok(Json(serde_json::json!({ - "name": "Conduwuit", + "name": "conduwuit", "version": conduwuit_version(), }))) } + +/// # `GET /_conduwuit/local_user_count` +/// +/// conduwuit-specific API to return the amount of users registered on this +/// homeserver. Endpoint is disabled if federation is disabled for privacy. This +/// only includes active users (not deactivated, no guests, etc) +pub(crate) async fn conduwuit_local_user_count() -> Result { + let user_count = services().users.list_local_users()?.len(); + + Ok(Json(serde_json::json!({ + "count": user_count + }))) +} diff --git a/src/api/router.rs b/src/api/router.rs index 3ad88819..3cb4a800 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -220,11 +220,13 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(server_server::claim_keys_route) .ruma_route(server_server::get_hierarchy_route) .ruma_route(server_server::well_known_server) + .route("/_conduwuit/local_user_count", get(client_server::conduwuit_local_user_count)) } else { router .route("/_matrix/federation/*path", any(federation_disabled)) .route("/.well-known/matrix/server", any(federation_disabled)) .route("/_matrix/key/*path", any(federation_disabled)) + .route("/_conduwuit/local_user_count", any(federation_disabled)) } }