fix: join appservice room with alias

This commit is contained in:
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
.get("namespaces")
.and_then(|ns| ns.get("aliases"))
.and_then(|users| users.get("regex"))
.and_then(|aliases| aliases.as_sequence())
.map_or_else(Vec::new, |aliases| {
aliases
.iter()
.map(|aliases| {
aliases
.get("regex")
.and_then(|regex| regex.as_str())
.and_then(|regex| Regex::new(regex).ok());
.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
.sending
.send_appservice_request(

View File

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