Merge pull request 'Support fi.mau.room_id, and fully qualified room_id in /createRoom' (#777) from nex/custom-room-id into main

Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/777
Reviewed-by: Jade Ellis <jade@ellis.link>
This commit is contained in:
nex 2025-04-20 20:29:18 +00:00
commit 1c59b41ff1
3 changed files with 40 additions and 30 deletions

View file

@ -107,7 +107,6 @@ pub(crate) async fn create_room_route(
return Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")));
}
let _short_id = services
.rooms
.short
@ -606,24 +605,35 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<Own
return Err(Error::BadRequest(ErrorKind::Unknown, "Custom room ID is forbidden."));
}
if custom_room_id.contains(':') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained `:` which is not allowed. Please note that this expects a \
localpart, not the full room ID.",
));
} else if custom_room_id.contains(char::is_whitespace) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained spaces which is not valid.",
));
}
let server_name = services.globals.server_name();
let full_room_id = format!("!{custom_room_id}:{server_name}");
OwnedRoomId::parse(full_room_id)
let mut room_id = custom_room_id.to_owned();
if custom_room_id.contains(':') {
if !custom_room_id.starts_with('!') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contains an unexpected `:` which is not allowed.",
));
}
} else if custom_room_id.starts_with('!'){
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room ID is prefixed with !, but is not fully qualified. You likely did not want this."));
} else {
room_id = format!("!{custom_room_id}:{server_name}");
}
OwnedRoomId::parse(room_id)
.map_err(Into::into)
.inspect(|full_room_id| debug_info!(?full_room_id, "Full custom room ID"))
.and_then(
|full_room_id| {
if full_room_id.server_name().expect("failed to extract server name from room ID") != server_name {
Err(Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID must be on this server."))
} else {
Ok(full_room_id)
}
}
)
.inspect(|full_room_id| {
debug_info!(?full_room_id, "Full custom room ID");
})
.inspect_err(|e| warn!(?e, ?custom_room_id, "Failed to create room with custom room ID",))
}