#[non_exhaustive]pub struct Ruleset {
pub content: IndexSet<PatternedPushRule>,
pub override_: IndexSet<ConditionalPushRule>,
pub room: IndexSet<SimplePushRule<OwnedRoomId>>,
pub sender: IndexSet<SimplePushRule<OwnedUserId>>,
pub underride: IndexSet<ConditionalPushRule>,
}
Expand description
A push ruleset scopes a set of rules according to some criteria.
For example, some rules may only be applied for messages from a particular sender, a particular room, or by default. The push ruleset contains the entire set of scopes and rules.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.content: IndexSet<PatternedPushRule>
These rules configure behavior for (unencrypted) messages that match certain patterns.
override_: IndexSet<ConditionalPushRule>
These user-configured rules are given the highest priority.
This field is named override_
instead of override
because the latter is a reserved
keyword in Rust.
room: IndexSet<SimplePushRule<OwnedRoomId>>
These rules change the behavior of all messages for a given room.
sender: IndexSet<SimplePushRule<OwnedUserId>>
These rules configure notification behavior for messages from a specific Matrix user ID.
underride: IndexSet<ConditionalPushRule>
These rules are identical to override rules, but have a lower priority than content
,
room
and sender
rules.
Implementations§
Source§impl Ruleset
impl Ruleset
Sourcepub fn server_default(user_id: &UserId) -> Self
pub fn server_default(user_id: &UserId) -> Self
The list of all predefined push rules.
§Parameters
user_id
: the user for which to generate the default rules. Some rules depend on the user’s ID (for instance those to send notifications when they are mentioned).
Sourcepub fn update_with_server_default(&mut self, new_server_default: Ruleset)
pub fn update_with_server_default(&mut self, new_server_default: Ruleset)
Update this ruleset with the given server-default push rules.
This will replace the server-default rules in this ruleset (with default
set to true
)
with the given ones while keeping the enabled
and actions
fields in the same state.
The default rules in this ruleset that are not in the new server-default rules are removed.
§Parameters
server_default
: the new server-default push rules. This ruleset must not contain non-default rules.
Source§impl Ruleset
impl Ruleset
Sourcepub fn iter(&self) -> RulesetIter<'_> ⓘ
pub fn iter(&self) -> RulesetIter<'_> ⓘ
Creates a borrowing iterator over all push rules in this Ruleset
.
For an owning iterator, use .into_iter()
.
Sourcepub fn insert(
&mut self,
rule: NewPushRule,
after: Option<&str>,
before: Option<&str>,
) -> Result<(), InsertPushRuleError>
pub fn insert( &mut self, rule: NewPushRule, after: Option<&str>, before: Option<&str>, ) -> Result<(), InsertPushRuleError>
Inserts a user-defined rule in the rule set.
If a rule with the same kind and rule_id
exists, it will be replaced.
If after
or before
is set, the rule will be moved relative to the rule with the given
ID. If both are set, the rule will become the next-most important rule with respect to
before
. If neither are set, and the rule is newly inserted, it will become the rule with
the highest priority of its kind.
Returns an error if the parameters are invalid.
Sourcepub fn get(
&self,
kind: RuleKind,
rule_id: impl AsRef<str>,
) -> Option<AnyPushRuleRef<'_>>
pub fn get( &self, kind: RuleKind, rule_id: impl AsRef<str>, ) -> Option<AnyPushRuleRef<'_>>
Get the rule from the given kind and with the given rule_id
in the rule set.
Sourcepub fn set_enabled(
&mut self,
kind: RuleKind,
rule_id: impl AsRef<str>,
enabled: bool,
) -> Result<(), RuleNotFoundError>
pub fn set_enabled( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, enabled: bool, ) -> Result<(), RuleNotFoundError>
Set whether the rule from the given kind and with the given rule_id
in the rule set is
enabled.
Returns an error if the rule can’t be found.
Sourcepub fn set_actions(
&mut self,
kind: RuleKind,
rule_id: impl AsRef<str>,
actions: Vec<Action>,
) -> Result<(), RuleNotFoundError>
pub fn set_actions( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, actions: Vec<Action>, ) -> Result<(), RuleNotFoundError>
Set the actions of the rule from the given kind and with the given rule_id
in the rule
set.
Returns an error if the rule can’t be found.
Sourcepub fn get_match<T>(
&self,
event: &Raw<T>,
context: &PushConditionRoomCtx,
) -> Option<AnyPushRuleRef<'_>>
pub fn get_match<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> Option<AnyPushRuleRef<'_>>
Get the first push rule that applies to this event, if any.
§Arguments
event
- The raw JSON of a room message event.context
- The context of the message and room at the time of the event.
Sourcepub fn get_actions<T>(
&self,
event: &Raw<T>,
context: &PushConditionRoomCtx,
) -> &[Action]
pub fn get_actions<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> &[Action]
Get the push actions that apply to this event.
Returns an empty slice if no push rule applies.
§Arguments
event
- The raw JSON of a room message event.context
- The context of the message and room at the time of the event.