diff --git a/src/database/entities/server.rs b/src/database/entities/server.rs index 0953a99bbe9daec40285141f72b5849b70c0222e..9bf95c210c9e8905f701bc0a7fb172aff830257e 100644 --- a/src/database/entities/server.rs +++ b/src/database/entities/server.rs @@ -425,4 +425,19 @@ impl Server { Ok(()) } + + pub async fn get_member_count(id: &str) -> Result<i64> { + Ok(get_collection("server_members") + .count_documents( + doc! { + "_id.server": id + }, + None, + ) + .await + .map_err(|_| Error::DatabaseError { + operation: "count_documents", + with: "server_members", + })?) + } } diff --git a/src/routes/invites/invite_fetch.rs b/src/routes/invites/invite_fetch.rs index e76039d42479a15a3822b9937b5543d4d7daab07..a905c2dd89b18f216eb773147a68bf49e3f3f52d 100644 --- a/src/routes/invites/invite_fetch.rs +++ b/src/routes/invites/invite_fetch.rs @@ -21,6 +21,7 @@ pub enum InviteResponse { user_name: String, #[serde(skip_serializing_if = "Option::is_none")] user_avatar: Option<File>, + member_count: i64, }, } @@ -41,6 +42,7 @@ pub async fn req(target: Ref) -> Result<JsonValue> { let server = Ref::from_unchecked(server).fetch_server().await?; Ok(json!(InviteResponse::Server { + member_count: Server::get_member_count(&server.id).await?, server_id: server.id, server_name: server.name, server_icon: server.icon,