diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index 980d6c60..4e9a16eb 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -35,6 +35,7 @@ Improvements: * Stabilize support for event replacements (edits) * Add support for read receipts for threads (MSC3771 / Matrix 1.4) * Add `push::PredefinedRuleId` and associated types as a list of predefined push rule IDs +* Add `Ruleset::get` to access push rules. # 0.10.5 diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index 16e53900..b3ec62ba 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -85,6 +85,20 @@ impl Ruleset { self.into_iter() } + /// Get the rule from the given kind and with the given `rule_id` in the rule set. + pub fn get(&self, kind: RuleKind, rule_id: impl AsRef) -> Option> { + let rule_id = rule_id.as_ref(); + + match kind { + RuleKind::Override => self.override_.get(rule_id).map(AnyPushRuleRef::Override), + RuleKind::Underride => self.underride.get(rule_id).map(AnyPushRuleRef::Underride), + RuleKind::Sender => self.sender.get(rule_id).map(AnyPushRuleRef::Sender), + RuleKind::Room => self.room.get(rule_id).map(AnyPushRuleRef::Room), + RuleKind::Content => self.content.get(rule_id).map(AnyPushRuleRef::Content), + RuleKind::_Custom(_) => None, + } + } + /// Get the first push rule that applies to this event, if any. /// /// # Arguments