@@ -22,9 +22,7 @@ use ruma::{events::AnyTimelineEvent, serde::Raw};
22
22
use serde:: { ser:: SerializeSeq , Deserialize , Deserializer , Serialize , Serializer } ;
23
23
use tracing:: { debug, error} ;
24
24
25
- use super :: {
26
- filter:: MatrixEventFilterInput , EventFilter , MessageLikeEventFilter , StateEventFilter ,
27
- } ;
25
+ use super :: { filter:: FilterInput , Filter , MessageLikeEventFilter , StateEventFilter } ;
28
26
29
27
/// Must be implemented by a component that provides functionality of deciding
30
28
/// whether a widget is allowed to use certain capabilities (typically by
@@ -42,9 +40,9 @@ pub trait CapabilitiesProvider: Send + Sync + 'static {
42
40
#[ cfg_attr( test, derive( PartialEq ) ) ]
43
41
pub struct Capabilities {
44
42
/// Types of the messages that a widget wants to be able to fetch.
45
- pub read : Vec < EventFilter > ,
43
+ pub read : Vec < Filter > ,
46
44
/// Types of the messages that a widget wants to be able to send.
47
- pub send : Vec < EventFilter > ,
45
+ pub send : Vec < Filter > ,
48
46
/// If this capability is requested by the widget, it can not operate
49
47
/// separately from the matrix client.
50
48
///
@@ -60,7 +58,7 @@ pub struct Capabilities {
60
58
impl Capabilities {
61
59
/// Tells if a given raw event matches the read filter.
62
60
pub fn raw_event_matches_read_filter ( & self , raw : & Raw < AnyTimelineEvent > ) -> bool {
63
- let filter_in = match raw. deserialize_as :: < MatrixEventFilterInput > ( ) {
61
+ let filter_in = match raw. deserialize_as :: < FilterInput > ( ) {
64
62
Ok ( filter) => filter,
65
63
Err ( err) => {
66
64
error ! ( "Failed to deserialize raw event as MatrixEventFilterInput: {err}" ) ;
@@ -85,12 +83,12 @@ impl Serialize for Capabilities {
85
83
where
86
84
S : Serializer ,
87
85
{
88
- struct PrintEventFilter < ' a > ( & ' a EventFilter ) ;
86
+ struct PrintEventFilter < ' a > ( & ' a Filter ) ;
89
87
impl fmt:: Display for PrintEventFilter < ' _ > {
90
88
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
91
89
match self . 0 {
92
- EventFilter :: MessageLike ( filter) => PrintMessageLikeEventFilter ( filter) . fmt ( f) ,
93
- EventFilter :: State ( filter) => PrintStateEventFilter ( filter) . fmt ( f) ,
90
+ Filter :: MessageLike ( filter) => PrintMessageLikeEventFilter ( filter) . fmt ( f) ,
91
+ Filter :: State ( filter) => PrintStateEventFilter ( filter) . fmt ( f) ,
94
92
}
95
93
}
96
94
}
@@ -136,15 +134,15 @@ impl Serialize for Capabilities {
136
134
}
137
135
for filter in & self . read {
138
136
let name = match filter {
139
- EventFilter :: MessageLike ( _) => READ_EVENT ,
140
- EventFilter :: State ( _) => READ_STATE ,
137
+ Filter :: MessageLike ( _) => READ_EVENT ,
138
+ Filter :: State ( _) => READ_STATE ,
141
139
} ;
142
140
seq. serialize_element ( & format ! ( "{name}:{}" , PrintEventFilter ( filter) ) ) ?;
143
141
}
144
142
for filter in & self . send {
145
143
let name = match filter {
146
- EventFilter :: MessageLike ( _) => SEND_EVENT ,
147
- EventFilter :: State ( _) => SEND_STATE ,
144
+ Filter :: MessageLike ( _) => SEND_EVENT ,
145
+ Filter :: State ( _) => SEND_STATE ,
148
146
} ;
149
147
seq. serialize_element ( & format ! ( "{name}:{}" , PrintEventFilter ( filter) ) ) ?;
150
148
}
@@ -162,8 +160,8 @@ impl<'de> Deserialize<'de> for Capabilities {
162
160
RequiresClient ,
163
161
UpdateDelayedEvent ,
164
162
SendDelayedEvent ,
165
- Read ( EventFilter ) ,
166
- Send ( EventFilter ) ,
163
+ Read ( Filter ) ,
164
+ Send ( Filter ) ,
167
165
Unknown ,
168
166
}
169
167
@@ -184,17 +182,17 @@ impl<'de> Deserialize<'de> for Capabilities {
184
182
}
185
183
186
184
match s. split_once ( ':' ) {
187
- Some ( ( READ_EVENT , filter_s) ) => Ok ( Permission :: Read ( EventFilter :: MessageLike (
185
+ Some ( ( READ_EVENT , filter_s) ) => Ok ( Permission :: Read ( Filter :: MessageLike (
188
186
parse_message_event_filter ( filter_s) ,
189
187
) ) ) ,
190
- Some ( ( SEND_EVENT , filter_s) ) => Ok ( Permission :: Send ( EventFilter :: MessageLike (
188
+ Some ( ( SEND_EVENT , filter_s) ) => Ok ( Permission :: Send ( Filter :: MessageLike (
191
189
parse_message_event_filter ( filter_s) ,
192
190
) ) ) ,
193
191
Some ( ( READ_STATE , filter_s) ) => {
194
- Ok ( Permission :: Read ( EventFilter :: State ( parse_state_event_filter ( filter_s) ) ) )
192
+ Ok ( Permission :: Read ( Filter :: State ( parse_state_event_filter ( filter_s) ) ) )
195
193
}
196
194
Some ( ( SEND_STATE , filter_s) ) => {
197
- Ok ( Permission :: Send ( EventFilter :: State ( parse_state_event_filter ( filter_s) ) ) )
195
+ Ok ( Permission :: Send ( Filter :: State ( parse_state_event_filter ( filter_s) ) ) )
198
196
}
199
197
_ => {
200
198
debug ! ( "Unknown capability `{s}`" ) ;
@@ -272,19 +270,17 @@ mod tests {
272
270
let parsed = serde_json:: from_str :: < Capabilities > ( capabilities_str) . unwrap ( ) ;
273
271
let expected = Capabilities {
274
272
read : vec ! [
275
- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
273
+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType (
276
274
"org.matrix.rageshake_request" . into( ) ,
277
275
) ) ,
278
- EventFilter :: State ( StateEventFilter :: WithType ( StateEventType :: RoomMember ) ) ,
279
- EventFilter :: State ( StateEventFilter :: WithType (
280
- "org.matrix.msc3401.call.member" . into( ) ,
281
- ) ) ,
276
+ Filter :: State ( StateEventFilter :: WithType ( StateEventType :: RoomMember ) ) ,
277
+ Filter :: State ( StateEventFilter :: WithType ( "org.matrix.msc3401.call.member" . into( ) ) ) ,
282
278
] ,
283
279
send : vec ! [
284
- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
280
+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType (
285
281
"org.matrix.rageshake_request" . into( ) ,
286
282
) ) ,
287
- EventFilter :: State ( StateEventFilter :: WithTypeAndStateKey (
283
+ Filter :: State ( StateEventFilter :: WithTypeAndStateKey (
288
284
"org.matrix.msc3401.call.member" . into( ) ,
289
285
"@user:matrix.server" . into( ) ,
290
286
) ) ,
@@ -301,20 +297,16 @@ mod tests {
301
297
fn serialization_and_deserialization_are_symmetrical ( ) {
302
298
let capabilities = Capabilities {
303
299
read : vec ! [
304
- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
305
- "io.element.custom" . into( ) ,
306
- ) ) ,
307
- EventFilter :: State ( StateEventFilter :: WithType ( StateEventType :: RoomMember ) ) ,
308
- EventFilter :: State ( StateEventFilter :: WithTypeAndStateKey (
300
+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType ( "io.element.custom" . into( ) ) ) ,
301
+ Filter :: State ( StateEventFilter :: WithType ( StateEventType :: RoomMember ) ) ,
302
+ Filter :: State ( StateEventFilter :: WithTypeAndStateKey (
309
303
"org.matrix.msc3401.call.member" . into( ) ,
310
304
"@user:matrix.server" . into( ) ,
311
305
) ) ,
312
306
] ,
313
307
send : vec ! [
314
- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
315
- "io.element.custom" . into( ) ,
316
- ) ) ,
317
- EventFilter :: State ( StateEventFilter :: WithTypeAndStateKey (
308
+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType ( "io.element.custom" . into( ) ) ) ,
309
+ Filter :: State ( StateEventFilter :: WithTypeAndStateKey (
318
310
"org.matrix.msc3401.call.member" . into( ) ,
319
311
"@user:matrix.server" . into( ) ,
320
312
) ) ,
0 commit comments