fix: join appservice room with alias

next
Timo Kösters 2021-03-18 12:03:15 +01:00
parent a77fcd106e
commit a0fa0ee7a0
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
2 changed files with 32 additions and 12 deletions

View File

@ -90,11 +90,23 @@ pub async fn get_alias_helper(
let aliases = registration let aliases = registration
.get("namespaces") .get("namespaces")
.and_then(|ns| ns.get("aliases")) .and_then(|ns| ns.get("aliases"))
.and_then(|users| users.get("regex")) .and_then(|aliases| aliases.as_sequence())
.and_then(|regex| regex.as_str()) .map_or_else(Vec::new, |aliases| {
.and_then(|regex| Regex::new(regex).ok()); aliases
.iter()
.map(|aliases| {
aliases
.get("regex")
.and_then(|regex| regex.as_str())
.and_then(|regex| Regex::new(regex).ok())
})
.filter_map(|o| o)
.collect::<Vec<_>>()
});
if aliases.map_or(false, |aliases| aliases.is_match(room_alias.as_str())) if aliases
.iter()
.any(|aliases| aliases.is_match(room_alias.as_str()))
&& db && db
.sending .sending
.send_appservice_request( .send_appservice_request(

View File

@ -1142,15 +1142,23 @@ impl Rooms {
}); });
let aliases = namespaces let aliases = namespaces
.get("aliases") .get("aliases")
.and_then(|users| users.get("regex")) .and_then(|aliases| aliases.as_sequence())
.and_then(|regex| regex.as_str()) .map_or_else(Vec::new, |aliases| {
.and_then(|regex| Regex::new(regex).ok()); aliases
.iter()
.map(|aliases| {
aliases
.get("regex")
.and_then(|regex| regex.as_str())
.and_then(|regex| Regex::new(regex).ok())
})
.filter_map(|o| o)
.collect::<Vec<_>>()
});
let rooms = namespaces let rooms = namespaces
.get("rooms") .get("rooms")
.and_then(|rooms| rooms.as_sequence()); .and_then(|rooms| rooms.as_sequence());
let room_aliases = self.room_aliases(&room_id);
let bridge_user_id = appservice let bridge_user_id = appservice
.1 .1
.get("sender_localpart") .get("sender_localpart")
@ -1170,15 +1178,15 @@ impl Rooms {
.as_ref() .as_ref()
.map_or(false, |state_key| users.is_match(&state_key)) .map_or(false, |state_key| users.is_match(&state_key))
}; };
let matching_aliases = |aliases: Regex| { let matching_aliases = |aliases: &Regex| {
room_aliases self.room_aliases(&room_id)
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.any(|room_alias| aliases.is_match(room_alias.as_str())) .any(|room_alias| aliases.is_match(room_alias.as_str()))
}; };
if bridge_user_id.map_or(false, user_is_joined) if bridge_user_id.map_or(false, user_is_joined)
|| users.iter().any(matching_users) || users.iter().any(matching_users)
|| aliases.map_or(false, matching_aliases) || aliases.iter().any(matching_aliases)
|| rooms.map_or(false, |rooms| rooms.contains(&room_id.as_str().into())) || rooms.map_or(false, |rooms| rooms.contains(&room_id.as_str().into()))
{ {
db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?; db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?;