Skip to main content

tuwunel_api/client/admin/rooms/
room_members.rs

1use axum::extract::State;
2use futures::StreamExt;
3use ruma::OwnedUserId;
4use synapse_admin_api::rooms::room_members::v1::{Request, Response};
5use tuwunel_core::{Err, Result};
6
7use super::usize_to_uint;
8use crate::{Ruma, client::admin::require_admin};
9
10/// # `GET /_synapse/admin/v1/rooms/{room_id}/members`
11///
12/// Lists the joined members of a room, local and remote. No pagination.
13pub(crate) async fn admin_room_members_route(
14	State(services): State<crate::State>,
15	body: Ruma<Request>,
16) -> Result<Response> {
17	require_admin(&services, body.sender_user()).await?;
18
19	if !services.metadata.exists(&body.room_id).await {
20		return Err!(Request(NotFound("Room not found")));
21	}
22
23	let members: Vec<OwnedUserId> = services
24		.state_cache
25		.room_members(&body.room_id)
26		.map(ToOwned::to_owned)
27		.collect()
28		.await;
29
30	let total = usize_to_uint(members.len());
31
32	Ok(Response { members, total })
33}