fix(appservices): don't panic on empty registration url

perf(appservices): cache regex for namespaces
This commit is contained in:
Matthias Ahouansou 2023-12-27 13:22:21 +00:00
parent a095e02d04
commit fa930182ae
No known key found for this signature in database
15 changed files with 335 additions and 244 deletions

View file

@ -81,12 +81,9 @@ where
let mut json_body = serde_json::from_slice::<CanonicalJsonValue>(&body).ok();
let appservices = services().appservice.all().unwrap();
let appservice_registration = appservices.iter().find(|(_id, registration)| {
registration
.get("as_token")
.and_then(|as_token| as_token.as_str())
.map_or(false, |as_token| token == Some(as_token))
});
let appservice_registration = appservices
.iter()
.find(|(_id, registration)| Some(registration.as_token.as_str()) == token);
let (sender_user, sender_device, sender_servername, from_appservice) =
if let Some((_id, registration)) = appservice_registration {
@ -95,11 +92,7 @@ where
let user_id = query_params.user_id.map_or_else(
|| {
UserId::parse_with_server_name(
registration
.get("sender_localpart")
.unwrap()
.as_str()
.unwrap(),
registration.sender_localpart.as_str(),
services().globals.server_name(),
)
.unwrap()