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