fix matrix-appservice-irc workaround

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-11-24 23:46:34 -05:00
parent 62d560e2fb
commit b20bd65d38

View file

@ -55,8 +55,15 @@ pub(crate) async fn get_register_available_route(
|| appservice.registration.id.contains("matrix_appservice_irc") || appservice.registration.id.contains("matrix_appservice_irc")
}); });
// don't force the username lowercase if it's from matrix-appservice-irc
let body_username = if is_matrix_appservice_irc {
body.username.clone()
} else {
body.username.to_lowercase()
};
// Validate user id // Validate user id
let user_id = UserId::parse_with_server_name(body.username.to_lowercase(), services.globals.server_name()) let user_id = UserId::parse_with_server_name(body_username, services.globals.server_name())
.ok() .ok()
.filter(|user_id| { .filter(|user_id| {
(!user_id.is_historical() || is_matrix_appservice_irc) && services.globals.user_is_local(user_id) (!user_id.is_historical() || is_matrix_appservice_irc) && services.globals.user_is_local(user_id)
@ -143,6 +150,8 @@ pub(crate) async fn register_route(
return Err(Error::BadRequest(ErrorKind::forbidden(), "Registration temporarily disabled.")); return Err(Error::BadRequest(ErrorKind::forbidden(), "Registration temporarily disabled."));
} }
let user_id = match (&body.username, is_guest) {
(Some(username), false) => {
// workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue // workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue
let is_matrix_appservice_irc = body.appservice_info.as_ref().is_some_and(|appservice| { let is_matrix_appservice_irc = body.appservice_info.as_ref().is_some_and(|appservice| {
appservice.registration.id == "irc" appservice.registration.id == "irc"
@ -150,14 +159,17 @@ pub(crate) async fn register_route(
|| appservice.registration.id.contains("matrix_appservice_irc") || appservice.registration.id.contains("matrix_appservice_irc")
}); });
let user_id = match (&body.username, is_guest) { // don't force the username lowercase if it's from matrix-appservice-irc
(Some(username), false) => { let body_username = if is_matrix_appservice_irc {
let proposed_user_id = username.clone()
UserId::parse_with_server_name(username.to_lowercase(), services.globals.server_name()) } else {
username.to_lowercase()
};
let proposed_user_id = UserId::parse_with_server_name(body_username, services.globals.server_name())
.ok() .ok()
.filter(|user_id| { .filter(|user_id| {
(!user_id.is_historical() || is_matrix_appservice_irc) (!user_id.is_historical() || is_matrix_appservice_irc) && services.globals.user_is_local(user_id)
&& services.globals.user_is_local(user_id)
}) })
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?; .ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;