From 0d33cc4acd9d17798c74922729f941b50bfb2fa8 Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sun, 11 Jul 2021 11:28:55 +0200 Subject: [PATCH] Implement getting room aliases Signed-off-by: Kurt Roeckx --- src/client_server/room.rs | 30 +++++++++++++++++++++++++++++- src/main.rs | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/client_server/room.rs b/src/client_server/room.rs index 6e27130..1fcf2d6 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -6,7 +6,7 @@ use log::info; use ruma::{ api::client::{ error::ErrorKind, - r0::room::{self, create_room, get_room_event, upgrade_room}, + r0::room::{self, aliases, create_room, get_room_event, upgrade_room}, }, events::{ room::{guest_access, history_visibility, join_rules, member, name, topic}, @@ -334,6 +334,34 @@ pub async fn get_room_event_route( .into()) } +#[cfg_attr( + feature = "conduit_bin", + get("/_matrix/client/r0/rooms/<_>/aliases", data = "") +)] +#[tracing::instrument(skip(db, body))] +pub async fn get_room_aliases_route( + db: DatabaseGuard, + body: Ruma>, +) -> ConduitResult { + let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + + if !db.rooms.is_joined(sender_user, &body.room_id)? { + return Err(Error::BadRequest( + ErrorKind::Forbidden, + "You don't have permission to view this room.", + )); + } + + Ok(aliases::Response { + aliases: db + .rooms + .room_aliases(&body.room_id) + .filter_map(|a| a.ok()) + .collect(), + } + .into()) +} + #[cfg_attr( feature = "conduit_bin", post("/_matrix/client/r0/rooms/<_room_id>/upgrade", data = "") diff --git a/src/main.rs b/src/main.rs index f69bc48..a5face7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,6 +60,7 @@ fn setup_rocket(config: Figment, data: Arc>) -> rocket::Rocket< client_server::set_pushrule_actions_route, client_server::delete_pushrule_route, client_server::get_room_event_route, + client_server::get_room_aliases_route, client_server::get_filter_route, client_server::create_filter_route, client_server::set_global_account_data_route,