Skip to main content

tuwunel_api/client/room/
aliases.rs

1use axum::extract::State;
2use futures::StreamExt;
3use ruma::api::client::room::aliases;
4use tuwunel_core::{Err, Result};
5
6use crate::Ruma;
7
8/// # `GET /_matrix/client/r0/rooms/{roomId}/aliases`
9///
10/// Lists all aliases of the room.
11///
12/// - Only users joined to the room are allowed to call this, or if
13///   `history_visibility` is world readable in the room
14pub(crate) async fn get_room_aliases_route(
15	State(services): State<crate::State>,
16	body: Ruma<aliases::v3::Request>,
17) -> Result<aliases::v3::Response> {
18	let sender_user = body.sender_user();
19
20	if !services
21		.state_accessor
22		.user_can_see_state_events(sender_user, &body.room_id)
23		.await
24	{
25		return Err!(Request(Forbidden("You don't have permission to view this room.",)));
26	}
27
28	Ok(aliases::v3::Response {
29		aliases: services
30			.alias
31			.local_aliases_for_room(&body.room_id)
32			.map(ToOwned::to_owned)
33			.collect()
34			.await,
35	})
36}