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

source

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).
source

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

source

pub fn new() -> Self

Creates an empty Ruleset.

source

pub fn iter(&self) -> RulesetIter<'_>

Creates a borrowing iterator over all push rules in this Ruleset.

For an owning iterator, use .into_iter().

source

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.

source

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.

source

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.

source

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.

source

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.
source

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.
source

pub fn remove( &mut self, kind: RuleKind, rule_id: impl AsRef<str> ) -> Result<(), RemovePushRuleError>

Removes a user-defined rule in the rule set.

Returns an error if the parameters are invalid.

Trait Implementations§

source§

impl Clone for Ruleset

source§

fn clone(&self) -> Ruleset

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ruleset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ruleset

source§

fn default() -> Ruleset

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Ruleset

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a> IntoIterator for &'a Ruleset

§

type Item = AnyPushRuleRef<'a>

The type of the elements being iterated over.
§

type IntoIter = RulesetIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Ruleset

§

type Item = AnyPushRule

The type of the elements being iterated over.
§

type IntoIter = RulesetIntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl Serialize for Ruleset

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

source§

const WITNESS: W = W::MAKE

A constant of the type witness
source§

impl<T> Identity for T
where T: ?Sized,

§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,