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) -> Ruleset
Available on crate feature events
only.
pub fn server_default(user_id: &UserId) -> Ruleset
events
only.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)
Available on crate feature events
only.
pub fn update_with_server_default(&mut self, new_server_default: Ruleset)
events
only.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<'_> ⓘ
Available on crate feature events
only.
pub fn iter(&self) -> RulesetIter<'_> ⓘ
events
only.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>
Available on crate feature events
only.
pub fn insert( &mut self, rule: NewPushRule, after: Option<&str>, before: Option<&str>, ) -> Result<(), InsertPushRuleError>
events
only.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<'_>>
Available on crate feature events
only.
pub fn get( &self, kind: RuleKind, rule_id: impl AsRef<str>, ) -> Option<AnyPushRuleRef<'_>>
events
only.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>
Available on crate feature events
only.
pub fn set_enabled( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, enabled: bool, ) -> Result<(), RuleNotFoundError>
events
only.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>
Available on crate feature events
only.
pub fn set_actions( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, actions: Vec<Action>, ) -> Result<(), RuleNotFoundError>
events
only.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<'_>>
Available on crate feature events
only.
pub fn get_match<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> Option<AnyPushRuleRef<'_>>
events
only.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]
Available on crate feature events
only.
pub fn get_actions<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> &[Action]
events
only.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<Ruleset, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Ruleset, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl From<Ruleset> for PushRulesEventContent
impl From<Ruleset> for PushRulesEventContent
source§fn from(global: Ruleset) -> PushRulesEventContent
fn from(global: Ruleset) -> PushRulesEventContent
source§impl<'a> IntoIterator for &'a Ruleset
impl<'a> IntoIterator for &'a Ruleset
source§type Item = AnyPushRuleRef<'a>
type Item = AnyPushRuleRef<'a>
source§type IntoIter = RulesetIter<'a>
type IntoIter = RulesetIter<'a>
source§impl IntoIterator for Ruleset
impl IntoIterator for Ruleset
source§type Item = AnyPushRule
type Item = AnyPushRule
source§type IntoIter = RulesetIntoIter
type IntoIter = RulesetIntoIter
source§impl Serialize for Ruleset
impl Serialize for Ruleset
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
)source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more