Struct ruma_common::push::Ruleset
source · 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§
§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.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Ruleset
impl<'de> Deserialize<'de> for Ruleset
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<'a> IntoIterator for &'a Ruleset
impl<'a> IntoIterator for &'a Ruleset
source§impl IntoIterator for Ruleset
impl IntoIterator for Ruleset
Auto Trait Implementations§
impl Freeze for Ruleset
impl RefUnwindSafe for Ruleset
impl Send for Ruleset
impl Sync for Ruleset
impl Unpin for Ruleset
impl UnwindSafe for Ruleset
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)