From 8a767c4b1087f48edbfdb8a48c33b364a7637ec2 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 21 Apr 2024 23:36:20 -0400 Subject: [PATCH] on room alias joins, attempt to find the room ID through *more* servers if available Signed-off-by: strawberry --- src/api/client_server/alias.rs | 130 ++++++++++++------ src/api/client_server/membership.rs | 2 +- .../admin/room/room_moderation_commands.rs | 6 +- 3 files changed, 91 insertions(+), 47 deletions(-) diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index 3fafee72..1345ef0c 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -10,8 +10,9 @@ use ruma::{ }, OwnedRoomAliasId, OwnedServerName, }; +use tracing::{debug, info}; -use crate::{services, Error, Result, Ruma}; +use crate::{debug_info, services, Error, Result, Ruma}; /// # `PUT /_matrix/client/v3/directory/room/{roomAlias}` /// @@ -118,12 +119,19 @@ pub async fn delete_alias_route(body: Ruma) -> Result /// /// Resolve an alias locally or over federation. pub async fn get_alias_route(body: Ruma) -> Result { - get_alias_helper(body.body.room_alias).await + get_alias_helper(body.body.room_alias, None).await } -pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result { - if room_alias.server_name() != services().globals.server_name() { - let response = services() +pub(crate) async fn get_alias_helper( + room_alias: OwnedRoomAliasId, servers: Option>, +) -> Result { + if room_alias.server_name() != services().globals.server_name() + && (!servers + .as_ref() + .is_some_and(|servers| servers.contains(&services().globals.server_name().to_owned())) + || servers.as_ref().is_none()) + { + let mut response = services() .sending .send_federation_request( room_alias.server_name(), @@ -131,47 +139,83 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result) -> federation" ); - match get_alias_helper(room_alias).await { + match get_alias_helper(room_alias, None).await { Ok(response) => { debug!("Got federation response fetching room ID for room {room}: {:?}", response); response.room_id @@ -233,7 +233,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> fetch room ID over federation" ); - match get_alias_helper(room_alias).await { + match get_alias_helper(room_alias, None).await { Ok(response) => { debug!( "Got federation response fetching room ID for room {room}: \ @@ -432,7 +432,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> federation" ); - match get_alias_helper(room_alias).await { + match get_alias_helper(room_alias, None).await { Ok(response) => { debug!("Got federation response fetching room ID for room {room}: {:?}", response); response.room_id