mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-24 16:48:52 -04:00
sdk: Split widget EventFilter into sub-types
… and move them into their own module. Co-authored-by: Timo K <toger5@hotmail.de> Co-authored-by: Daniel Abramov <inetcrack2@gmail.com>
This commit is contained in:
committed by
Jonas Platte
parent
c589bd0cd1
commit
04fee2952f
@@ -1,6 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use matrix_sdk::async_trait;
|
||||
use matrix_sdk::{
|
||||
async_trait,
|
||||
widget::{MessageLikeEventFilter, StateEventFilter},
|
||||
};
|
||||
|
||||
use crate::room::Room;
|
||||
|
||||
@@ -74,31 +77,30 @@ impl From<matrix_sdk::widget::Permissions> for WidgetPermissions {
|
||||
/// Different kinds of filters that could be applied to the timeline events.
|
||||
#[derive(uniffi::Enum)]
|
||||
pub enum WidgetEventFilter {
|
||||
/// Message-like events.
|
||||
MessageLike {
|
||||
/// The type of the message-like event.
|
||||
event_type: String,
|
||||
/// Additional filter for the msgtype, currently only used for
|
||||
/// `m.room.message`.
|
||||
msgtype: Option<String>,
|
||||
},
|
||||
/// State events.
|
||||
State {
|
||||
/// The type of the state event.
|
||||
event_type: String,
|
||||
/// State key that could be `None`, `None` means "any state key".
|
||||
state_key: Option<String>,
|
||||
},
|
||||
/// Matches message-like events with the given `type`.
|
||||
MessageLikeWithType { event_type: String },
|
||||
/// Matches `m.room.message` events with the given `msgtype`.
|
||||
RoomMessageWithMsgtype { msgtype: String },
|
||||
/// Matches state events with the given `type`, regardless of `state_key`.
|
||||
StateWithType { event_type: String },
|
||||
/// Matches state events with the given `type` and `state_key`.
|
||||
StateWithTypeAndStateKey { event_type: String, state_key: String },
|
||||
}
|
||||
|
||||
impl From<WidgetEventFilter> for matrix_sdk::widget::EventFilter {
|
||||
fn from(value: WidgetEventFilter) -> Self {
|
||||
match value {
|
||||
WidgetEventFilter::MessageLike { event_type, msgtype } => {
|
||||
Self::MessageLike { event_type: event_type.into(), msgtype }
|
||||
WidgetEventFilter::MessageLikeWithType { event_type } => {
|
||||
Self::MessageLike(MessageLikeEventFilter::WithType(event_type.into()))
|
||||
}
|
||||
WidgetEventFilter::State { event_type, state_key } => {
|
||||
Self::State { event_type: event_type.into(), state_key }
|
||||
WidgetEventFilter::RoomMessageWithMsgtype { msgtype } => {
|
||||
Self::MessageLike(MessageLikeEventFilter::RoomMessageWithMsgtype(msgtype))
|
||||
}
|
||||
WidgetEventFilter::StateWithType { event_type } => {
|
||||
Self::State(StateEventFilter::WithType(event_type.into()))
|
||||
}
|
||||
WidgetEventFilter::StateWithTypeAndStateKey { event_type, state_key } => {
|
||||
Self::State(StateEventFilter::WithTypeAndStateKey(event_type.into(), state_key))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,11 +111,17 @@ impl From<matrix_sdk::widget::EventFilter> for WidgetEventFilter {
|
||||
use matrix_sdk::widget::EventFilter as F;
|
||||
|
||||
match value {
|
||||
F::MessageLike { event_type, msgtype } => {
|
||||
Self::MessageLike { event_type: event_type.to_string(), msgtype }
|
||||
F::MessageLike(MessageLikeEventFilter::WithType(event_type)) => {
|
||||
Self::MessageLikeWithType { event_type: event_type.to_string() }
|
||||
}
|
||||
F::State { event_type, state_key } => {
|
||||
Self::State { event_type: event_type.to_string(), state_key }
|
||||
F::MessageLike(MessageLikeEventFilter::RoomMessageWithMsgtype(msgtype)) => {
|
||||
Self::RoomMessageWithMsgtype { msgtype }
|
||||
}
|
||||
F::State(StateEventFilter::WithType(event_type)) => {
|
||||
Self::StateWithType { event_type: event_type.to_string() }
|
||||
}
|
||||
F::State(StateEventFilter::WithTypeAndStateKey(event_type, state_key)) => {
|
||||
Self::StateWithTypeAndStateKey { event_type: event_type.to_string(), state_key }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
crates/matrix-sdk/src/widget/filter.rs
Normal file
28
crates/matrix-sdk/src/widget/filter.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use ruma::events::{MessageLikeEventType, StateEventType};
|
||||
|
||||
/// Different kinds of filters for timeline events.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum EventFilter {
|
||||
/// Filter for message-like events.
|
||||
MessageLike(MessageLikeEventFilter),
|
||||
/// Filter for state events.
|
||||
State(StateEventFilter),
|
||||
}
|
||||
|
||||
/// Filter for message-like events.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MessageLikeEventFilter {
|
||||
/// Matches message-like events with the given `type`.
|
||||
WithType(MessageLikeEventType),
|
||||
/// Matches `m.room.message` events with the given `msgtype`.
|
||||
RoomMessageWithMsgtype(String),
|
||||
}
|
||||
|
||||
/// Filter for state events.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum StateEventFilter {
|
||||
/// Matches state events with the given `type`, regardless of `state_key`.
|
||||
WithType(StateEventType),
|
||||
/// Matches state events with the given `type` and `state_key`.
|
||||
WithTypeAndStateKey(StateEventType, String),
|
||||
}
|
||||
@@ -4,9 +4,13 @@ use async_channel::{Receiver, Sender};
|
||||
|
||||
use crate::room::Room as JoinedRoom;
|
||||
|
||||
mod filter;
|
||||
mod permissions;
|
||||
|
||||
pub use self::permissions::{EventFilter, Permissions, PermissionsProvider};
|
||||
pub use self::{
|
||||
filter::{EventFilter, MessageLikeEventFilter, StateEventFilter},
|
||||
permissions::{Permissions, PermissionsProvider},
|
||||
};
|
||||
|
||||
/// Describes a widget.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::ruma::events::{MessageLikeEventType, StateEventType};
|
||||
use super::EventFilter;
|
||||
|
||||
/// Must be implemented by a component that provides functionality of deciding
|
||||
/// whether a widget is allowed to use certain capabilities (typically by
|
||||
@@ -24,23 +24,3 @@ pub struct Permissions {
|
||||
/// Types of the messages that a widget wants to be able to send.
|
||||
pub send: Vec<EventFilter>,
|
||||
}
|
||||
|
||||
/// Different kinds of filters that could be applied to the timeline events.
|
||||
#[derive(Debug)]
|
||||
pub enum EventFilter {
|
||||
/// Message-like events.
|
||||
MessageLike {
|
||||
/// The type of the message-like event.
|
||||
event_type: MessageLikeEventType,
|
||||
/// Additional filter for the msgtype, currently only used for
|
||||
/// `m.room.message`.
|
||||
msgtype: Option<String>,
|
||||
},
|
||||
/// State events.
|
||||
State {
|
||||
/// The type of the state event.
|
||||
event_type: StateEventType,
|
||||
/// State key that could be `None`, `None` means "any state key".
|
||||
state_key: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user