Skip to main content

tuwunel_api/client/admin/users/
list_joined_rooms.rs

1use axum::extract::State;
2use futures::StreamExt;
3use synapse_admin_api::users::list_joined_rooms::v1 as list_joined_rooms;
4use tuwunel_core::{Result, utils::math::ruma_from_usize};
5
6use crate::{Ruma, client::admin::require_admin};
7
8/// # `GET /_synapse/admin/v1/users/{user_id}/joined_rooms`
9///
10/// For remote users this lists only the rooms shared with this server, matching
11/// Synapse.
12pub(crate) async fn admin_list_joined_rooms_route(
13	State(services): State<crate::State>,
14	body: Ruma<list_joined_rooms::Request>,
15) -> Result<list_joined_rooms::Response> {
16	require_admin(&services, body.sender_user()).await?;
17
18	let joined_rooms = services
19		.state_cache
20		.rooms_joined(&body.user_id)
21		.map(ToOwned::to_owned)
22		.collect::<Vec<_>>()
23		.await;
24
25	let total = ruma_from_usize(joined_rooms.len());
26
27	Ok(list_joined_rooms::Response::new(joined_rooms, total))
28}