Skip to content

Commit

Permalink
add workaround for matrix-appservice-irc using historical localparts
Browse files Browse the repository at this point in the history
see matrix-org/matrix-appservice-irc#1780

Signed-off-by: strawberry <strawberry@puppygock.gay>
  • Loading branch information
girlbossceo committed Nov 3, 2024
1 parent 6f37a25 commit 0387871
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/api/client/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@ pub(crate) async fn get_register_available_route(
State(services): State<crate::State>, InsecureClientIp(client): InsecureClientIp,
body: Ruma<get_username_availability::v3::Request>,
) -> Result<get_username_availability::v3::Response> {
// 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| {
appservice.registration.id == "irc"
|| appservice.registration.id.contains("matrix-appservice-irc")
|| appservice.registration.id.contains("matrix_appservice_irc")
});

// Validate user id
let user_id = UserId::parse_with_server_name(body.username.to_lowercase(), services.globals.server_name())
.ok()
.filter(|user_id| !user_id.is_historical() && services.globals.user_is_local(user_id))
.filter(|user_id| {
(!user_id.is_historical() || is_matrix_appservice_irc) && services.globals.user_is_local(user_id)
})
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;

// Check if username is creative enough
Expand Down Expand Up @@ -134,12 +143,22 @@ pub(crate) async fn register_route(
return Err(Error::BadRequest(ErrorKind::forbidden(), "Registration temporarily disabled."));
}

// 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| {
appservice.registration.id == "irc"
|| appservice.registration.id.contains("matrix-appservice-irc")
|| appservice.registration.id.contains("matrix_appservice_irc")
});

let user_id = match (&body.username, is_guest) {
(Some(username), false) => {
let proposed_user_id =
UserId::parse_with_server_name(username.to_lowercase(), services.globals.server_name())
.ok()
.filter(|user_id| !user_id.is_historical() && services.globals.user_is_local(user_id))
.filter(|user_id| {
(!user_id.is_historical() || is_matrix_appservice_irc)
&& services.globals.user_is_local(user_id)
})
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;

if services.users.exists(&proposed_user_id).await {
Expand Down

0 comments on commit 0387871

Please sign in to comment.