mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-11 01:13:14 -04:00
WidgetDriver: filter event_type change from dedicated ...EventType -> String
This is (sadly) required since we cannot do `as_str()` for `TimlineEventType` and other `ruma` event types. So we need to use `String`. We also never used them more specifically than strings.
This commit is contained in:
@@ -197,34 +197,19 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_filter_matches_reaction() {
|
||||
assert!(reaction_event_filter().matches(&message_event(TimelineEventType::Reaction)));
|
||||
fn test_reaction_event_filter_matches_reaction() {
|
||||
assert!(reaction_event_filter()
|
||||
.matches(&message_event(&MessageLikeEventType::Reaction.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_filter_does_not_match_room_message() {
|
||||
assert!(!reaction_event_filter().matches(&message_event_with_msgtype(
|
||||
TimelineEventType::RoomMessage,
|
||||
"m.text".to_owned()
|
||||
)));
|
||||
fn test_reaction_event_filter_does_not_match_room_message() {
|
||||
assert!(!reaction_event_filter().matches(&FilterInput::message_with_msgtype("m.text")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_filter_does_not_match_state_event() {
|
||||
assert!(!reaction_event_filter().matches(&state_event(
|
||||
// Use the `m.reaction` event type to make sure the event would pass
|
||||
// the filter without state event checks, even though in practice
|
||||
// that event type won't be used for a state event.
|
||||
TimelineEventType::Reaction,
|
||||
"".to_owned()
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_filter_does_not_match_state_event_any_key() {
|
||||
assert!(
|
||||
!reaction_event_filter().matches_state_event_with_any_state_key(&"m.reaction".into())
|
||||
);
|
||||
fn test_reaction_event_filter_does_not_match_state_event_any_key() {
|
||||
assert!(!reaction_event_filter().matches(&FilterInput::state("m.reaction", "")));
|
||||
}
|
||||
|
||||
// Tests against an `m.room.member` filter with `state_key = "@self:example.me"`
|
||||
@@ -236,36 +221,37 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_member_event_filter_matches_self_member_event() {
|
||||
assert!(self_member_event_filter()
|
||||
.matches(&state_event(TimelineEventType::RoomMember, "@self:example.me".to_owned())));
|
||||
fn test_self_member_event_filter_matches_self_member_event() {
|
||||
assert!(self_member_event_filter().matches(&FilterInput::state(
|
||||
&TimelineEventType::RoomMember.to_string(),
|
||||
"@self:example.me"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_member_event_filter_does_not_match_somebody_elses_member_event() {
|
||||
assert!(!self_member_event_filter().matches(&state_event(
|
||||
TimelineEventType::RoomMember,
|
||||
"@somebody_else.example.me".to_owned()
|
||||
fn test_self_member_event_filter_does_not_match_somebody_elses_member_event() {
|
||||
assert!(!self_member_event_filter().matches(&FilterInput::state(
|
||||
&TimelineEventType::RoomMember.to_string(),
|
||||
"@somebody_else.example.me"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_member_event_filter_does_not_match_unrelated_state_event_with_same_state_key() {
|
||||
assert!(!self_member_event_filter().matches(&state_event(
|
||||
TimelineEventType::from("io.element.test_state_event"),
|
||||
"@self.example.me".to_owned()
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_member_event_filter_does_not_match_reaction_event() {
|
||||
assert!(!self_member_event_filter().matches(&message_event(TimelineEventType::Reaction)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_member_event_filter_only_matches_specific_state_key() {
|
||||
assert!(!self_member_event_filter()
|
||||
.matches_state_event_with_any_state_key(&StateEventType::RoomMember));
|
||||
.matches(&FilterInput::state("io.element.test_state_event", "@self.example.me")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_member_event_filter_does_not_match_reaction_event() {
|
||||
assert!(!self_member_event_filter()
|
||||
.matches(&message_event(&MessageLikeEventType::Reaction.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_member_event_filter_only_matches_specific_state_key() {
|
||||
assert!(!self_member_event_filter()
|
||||
.matches(&FilterInput::state(&StateEventType::RoomMember.to_string(), "")));
|
||||
}
|
||||
|
||||
// Tests against an `m.room.member` filter with any `state_key`.
|
||||
@@ -274,26 +260,29 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_event_filter_matches_some_member_event() {
|
||||
assert!(member_event_filter()
|
||||
.matches(&state_event(TimelineEventType::RoomMember, "@foo.bar.baz".to_owned())));
|
||||
fn test_member_event_filter_matches_some_member_event() {
|
||||
assert!(member_event_filter().matches(&FilterInput::state(
|
||||
&TimelineEventType::RoomMember.to_string(),
|
||||
"@foo.bar.baz"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_event_filter_does_not_match_room_name_event() {
|
||||
fn test_member_event_filter_does_not_match_room_name_event() {
|
||||
assert!(!member_event_filter()
|
||||
.matches(&state_event(TimelineEventType::RoomName, "".to_owned())));
|
||||
.matches(&FilterInput::state(&TimelineEventType::RoomName.to_string(), "")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_event_filter_does_not_match_reaction_event() {
|
||||
assert!(!member_event_filter().matches(&message_event(TimelineEventType::Reaction)));
|
||||
fn test_member_event_filter_does_not_match_reaction_event() {
|
||||
assert!(!member_event_filter()
|
||||
.matches(&message_event(&MessageLikeEventType::Reaction.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_event_filter_matches_any_state_key() {
|
||||
fn test_member_event_filter_matches_any_state_key() {
|
||||
assert!(member_event_filter()
|
||||
.matches_state_event_with_any_state_key(&StateEventType::RoomMember));
|
||||
.matches(&FilterInput::state(&StateEventType::RoomMember.to_string(), "")));
|
||||
}
|
||||
|
||||
// Tests against an `m.room.topic` filter with `state_key = ""`
|
||||
@@ -305,9 +294,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn topic_event_filter_does_not_match_any_state_key() {
|
||||
assert!(!topic_event_filter()
|
||||
.matches_state_event_with_any_state_key(&StateEventType::RoomTopic));
|
||||
fn test_topic_event_filter_does_match() {
|
||||
assert!(topic_event_filter()
|
||||
.matches(&FilterInput::state(&StateEventType::RoomTopic.to_string(), "")));
|
||||
}
|
||||
|
||||
// Tests against an `m.room.message` filter with `msgtype = m.custom`
|
||||
@@ -321,33 +310,27 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn room_message_event_type_matches_room_message_text_event_filter() {
|
||||
assert!(room_message_text_event_filter()
|
||||
.matches_message_like_event_type(&MessageLikeEventType::RoomMessage));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_type_does_not_match_room_message_text_event_filter() {
|
||||
fn test_reaction_event_type_does_not_match_room_message_text_event_filter() {
|
||||
assert!(!room_message_text_event_filter()
|
||||
.matches_message_like_event_type(&MessageLikeEventType::Reaction));
|
||||
.matches(&FilterInput::message_like(&MessageLikeEventType::Reaction.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn room_message_event_type_matches_room_message_custom_event_filter() {
|
||||
assert!(room_message_custom_event_filter()
|
||||
.matches_message_like_event_type(&MessageLikeEventType::RoomMessage));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaction_event_type_does_not_match_room_message_custom_event_filter() {
|
||||
fn test_room_message_event_without_msgtype_does_not_match_custom_msgtype_filter() {
|
||||
assert!(!room_message_custom_event_filter()
|
||||
.matches_message_like_event_type(&MessageLikeEventType::Reaction));
|
||||
.matches(&FilterInput::message_like(&MessageLikeEventType::RoomMessage.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn room_message_event_type_matches_room_message_event_filter() {
|
||||
fn test_reaction_event_type_does_not_match_room_message_custom_event_filter() {
|
||||
assert!(!room_message_custom_event_filter()
|
||||
.matches(&FilterInput::message_like(&MessageLikeEventType::Reaction.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_room_message_event_type_matches_room_message_event_filter() {
|
||||
assert!(room_message_filter()
|
||||
.matches_message_like_event_type(&MessageLikeEventType::RoomMessage));
|
||||
.matches(&FilterInput::message_like(&MessageLikeEventType::RoomMessage.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::marker::PhantomData;
|
||||
|
||||
use ruma::{
|
||||
api::client::{account::request_openid_token, delayed_events::update_delayed_event},
|
||||
events::{AnyTimelineEvent, MessageLikeEventType, StateEventType, TimelineEventType},
|
||||
events::AnyTimelineEvent,
|
||||
serde::Raw,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
@@ -157,7 +157,9 @@ impl FromMatrixDriverResponse for request_openid_token::v3::Response {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ReadMessageLikeEventRequest {
|
||||
/// The event type to read.
|
||||
pub(crate) event_type: MessageLikeEventType,
|
||||
// TODO: This wants to be `MessageLikeEventType`` but we need a type which supports `as_str()`
|
||||
// as soon as ruma supports `as_str()` on `MessageLikeEventType` we can use it here.
|
||||
pub(crate) event_type: String,
|
||||
|
||||
/// The maximum number of events to return.
|
||||
pub(crate) limit: u32,
|
||||
@@ -190,7 +192,9 @@ impl FromMatrixDriverResponse for Vec<Raw<AnyTimelineEvent>> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ReadStateEventRequest {
|
||||
/// The event type to read.
|
||||
pub(crate) event_type: StateEventType,
|
||||
// TODO: This wants to be `TimelineEventType` but we need a type which supports `as_str()`
|
||||
// as soon as ruma supports `as_str()` on `TimelineEventType` we can use it here.
|
||||
pub(crate) event_type: String,
|
||||
|
||||
/// The `state_key` to read, or `Any` to receive any/all events of the given
|
||||
/// type, regardless of their `state_key`.
|
||||
@@ -213,8 +217,10 @@ impl MatrixDriverRequest for ReadStateEventRequest {
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub(crate) struct SendEventRequest {
|
||||
/// The type of the event.
|
||||
// TODO: This wants to be `TimelineEventType` but we need a type which supports `as_str()`
|
||||
// as soon as ruma supports `as_str()` on `TimelineEventType` we can use it here.
|
||||
#[serde(rename = "type")]
|
||||
pub(crate) event_type: TimelineEventType,
|
||||
pub(crate) event_type: String,
|
||||
/// State key of an event (if it's a state event).
|
||||
pub(crate) state_key: Option<String>,
|
||||
/// Raw content of an event.
|
||||
|
||||
@@ -18,7 +18,7 @@ use ruma::{
|
||||
delayed_events::{delayed_message_event, delayed_state_event, update_delayed_event},
|
||||
error::{ErrorBody, StandardErrorBody},
|
||||
},
|
||||
events::{AnyTimelineEvent, MessageLikeEventType, StateEventType},
|
||||
events::AnyTimelineEvent,
|
||||
serde::Raw,
|
||||
OwnedEventId, OwnedRoomId,
|
||||
};
|
||||
@@ -178,12 +178,12 @@ pub(super) enum ApiVersion {
|
||||
pub(super) enum ReadEventRequest {
|
||||
ReadStateEvent {
|
||||
#[serde(rename = "type")]
|
||||
event_type: StateEventType,
|
||||
event_type: String,
|
||||
state_key: StateKeySelector,
|
||||
},
|
||||
ReadMessageLikeEvent {
|
||||
#[serde(rename = "type")]
|
||||
event_type: MessageLikeEventType,
|
||||
event_type: String,
|
||||
limit: Option<u32>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ fn parse_delayed_event_widget_action() {
|
||||
assert_let!(delay = send_event_request.delay.unwrap());
|
||||
|
||||
assert_eq!(delay, 10000);
|
||||
assert_eq!(send_event_request.event_type, TimelineEventType::CallMember);
|
||||
assert_eq!(send_event_request.event_type, TimelineEventType::CallMember.to_string());
|
||||
assert_eq!(send_event_request.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned());
|
||||
}
|
||||
|
||||
@@ -208,12 +208,12 @@ impl WidgetDriver {
|
||||
}
|
||||
|
||||
MatrixDriverRequestData::ReadMessageLikeEvent(cmd) => matrix_driver
|
||||
.read_message_like_events(cmd.event_type.clone(), cmd.limit)
|
||||
.read_message_like_events(cmd.event_type.into(), cmd.limit)
|
||||
.await
|
||||
.map(MatrixDriverResponse::MatrixEventRead),
|
||||
|
||||
MatrixDriverRequestData::ReadStateEvent(cmd) => matrix_driver
|
||||
.read_state_events(cmd.event_type.clone(), &cmd.state_key)
|
||||
.read_state_events(cmd.event_type.into(), &cmd.state_key)
|
||||
.await
|
||||
.map(MatrixDriverResponse::MatrixEventRead),
|
||||
|
||||
@@ -227,7 +227,7 @@ impl WidgetDriver {
|
||||
timeout: Duration::from_millis(d),
|
||||
});
|
||||
matrix_driver
|
||||
.send(event_type, state_key, content, delay_event_parameter)
|
||||
.send(event_type.into(), state_key, content, delay_event_parameter)
|
||||
.await
|
||||
.map(MatrixDriverResponse::MatrixEventSent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user