Skip to content

Commit

Permalink
implement MSC4210, add missing .m.rule.contains_user_name check
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <[email protected]>
  • Loading branch information
girlbossceo committed Oct 26, 2024
1 parent d96d981 commit 39c1add
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/ruma-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ unstable-msc3026 = []
unstable-msc3930 = []
unstable-msc3931 = []
unstable-msc3932 = ["unstable-msc3931"]
unstable-msc4210 = []
unstable-unspecified = []

# Allow IDs to exceed 255 bytes.
Expand Down
21 changes: 12 additions & 9 deletions crates/ruma-common/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ impl ConditionalPushRule {
return false;
}

// The old mention rules are disabled when an m.mentions field is present.
//
// MSC4210 always disables the legacy rules.
#[allow(deprecated)]
if (self.rule_id == PredefinedOverrideRuleId::RoomNotif.as_ref()
|| self.rule_id == PredefinedOverrideRuleId::ContainsDisplayName.as_ref()
|| self.rule_id == PredefinedContentRuleId::ContainsUserName.as_ref())
&& (event.contains_mentions() || cfg!(feature = "unstable-msc4210"))
{
return false;
}

#[cfg(feature = "unstable-msc3932")]
{
// These 3 rules always apply.
Expand All @@ -510,15 +522,6 @@ impl ConditionalPushRule {
}
}

// The old mention rules are disabled when an m.mentions field is present.
#[allow(deprecated)]
if (self.rule_id == PredefinedOverrideRuleId::RoomNotif.as_ref()
|| self.rule_id == PredefinedOverrideRuleId::ContainsDisplayName.as_ref())
&& event.contains_mentions()
{
return false;
}

self.conditions.iter().all(|cond| cond.applies(event, context))
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/ruma-common/src/push/predefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl Ruleset {
pub fn server_default(user_id: &UserId) -> Self {
Self {
content: [
#[cfg(not(feature = "unstable-msc4210"))]
#[allow(deprecated)]
PatternedPushRule::contains_user_name(user_id),
]
Expand All @@ -32,9 +33,11 @@ impl Ruleset {
ConditionalPushRule::invite_for_me(user_id),
ConditionalPushRule::member_event(),
ConditionalPushRule::is_user_mention(user_id),
#[cfg(not(feature = "unstable-msc4210"))]
#[allow(deprecated)]
ConditionalPushRule::contains_display_name(),
ConditionalPushRule::is_room_mention(),
#[cfg(not(feature = "unstable-msc4210"))]
#[allow(deprecated)]
ConditionalPushRule::roomnotif(),
ConditionalPushRule::tombstone(),
Expand Down
1 change: 1 addition & 0 deletions crates/ruma/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ unstable-msc4121 = ["ruma-client-api?/unstable-msc4121"]
unstable-msc4125 = ["ruma-federation-api?/unstable-msc4125"]
unstable-msc4140 = ["ruma-client-api?/unstable-msc4140"]
unstable-msc4186 = ["ruma-client-api?/unstable-msc4186"]
unstable-msc4210 = ["ruma-common/unstable-msc4210"]
unstable-pdu = ["ruma-events?/unstable-pdu"]
unstable-unspecified = [
"ruma-common/unstable-unspecified",
Expand Down

0 comments on commit 39c1add

Please sign in to comment.