From ca42ec338b3e01032f5fecc756f5070bf8ddd79d Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 23 Feb 2024 19:37:48 -0500 Subject: [PATCH] replace accidental unwraps with if let's this provides not only some future compatibility with MSC4051, but it just makes sense to not crash/error if we can't get a server_name from the room ID and should just use the server_name from the sender user's invite event. there is already code ahead that accounts for an empty vector so this is safe. Signed-off-by: strawberry --- src/api/client_server/membership.rs | 14 ++++++++++++-- src/service/rooms/spaces/mod.rs | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 32ee1948..3d2ef5e7 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -73,7 +73,12 @@ pub async fn join_room_by_id_route( .map(|user| user.server_name().to_owned()), ); - servers.push(body.room_id.server_name().unwrap().into()); + // server names being permanently attached to room IDs may be potentally removed in the future (see MSC4051). + // for future compatibility with this, and just because it makes sense, we shouldn't fail if the room ID + // doesn't have a server name with it and just use at least the server name from the initial invite above + if let Some(server) = body.room_id.server_name() { + servers.push(server.into()); + } join_room_by_id_helper( body.sender_user.as_deref(), @@ -123,7 +128,12 @@ pub async fn join_room_by_id_or_alias_route( .map(|user| user.server_name().to_owned()), ); - servers.push(room_id.server_name().unwrap().into()); + // server names being permanently attached to room IDs may be potentally removed in the future (see MSC4051). + // for future compatibility with this, and just because it makes sense, we shouldn't fail if the room ID + // doesn't have a server name with it and just use at least the server name from the initial invite above + if let Some(server) = room_id.server_name() { + servers.push(server.into()); + } (servers, room_id) } diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 677ba247..0174b48c 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -186,15 +186,16 @@ impl Service { if rooms_in_path.len() < max_depth { stack.push(children_ids); } - } else { - let server = current_room.server_name().unwrap(); + } else if let Some(server) = current_room.server_name() { if server == services().globals.server_name() { continue; } + if !results.is_empty() { // Early return so the client can see some data already break; } + debug!("Asking {server} for /hierarchy"); if let Ok(response) = services() .sending