@@ -22,9 +22,7 @@ use ruma::{events::AnyTimelineEvent, serde::Raw};
2222use serde:: { ser:: SerializeSeq , Deserialize , Deserializer , Serialize , Serializer } ;
2323use tracing:: { debug, error} ;
2424
25- use super :: {
26- filter:: MatrixEventFilterInput , EventFilter , MessageLikeEventFilter , StateEventFilter ,
27- } ;
25+ use super :: { filter:: FilterInput , Filter , MessageLikeEventFilter , StateEventFilter } ;
2826
2927/// Must be implemented by a component that provides functionality of deciding
3028/// whether a widget is allowed to use certain capabilities (typically by
@@ -42,9 +40,9 @@ pub trait CapabilitiesProvider: Send + Sync + 'static {
4240#[ cfg_attr( test, derive( PartialEq ) ) ]
4341pub struct Capabilities {
4442 /// Types of the messages that a widget wants to be able to fetch.
45- pub read : Vec < EventFilter > ,
43+ pub read : Vec < Filter > ,
4644 /// Types of the messages that a widget wants to be able to send.
47- pub send : Vec < EventFilter > ,
45+ pub send : Vec < Filter > ,
4846 /// If this capability is requested by the widget, it can not operate
4947 /// separately from the matrix client.
5048 ///
@@ -60,7 +58,7 @@ pub struct Capabilities {
6058impl Capabilities {
6159 /// Tells if a given raw event matches the read filter.
6260 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 > ( ) {
6462 Ok ( filter) => filter,
6563 Err ( err) => {
6664 error ! ( "Failed to deserialize raw event as MatrixEventFilterInput: {err}" ) ;
@@ -85,12 +83,12 @@ impl Serialize for Capabilities {
8583 where
8684 S : Serializer ,
8785 {
88- struct PrintEventFilter < ' a > ( & ' a EventFilter ) ;
86+ struct PrintEventFilter < ' a > ( & ' a Filter ) ;
8987 impl fmt:: Display for PrintEventFilter < ' _ > {
9088 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
9189 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) ,
9492 }
9593 }
9694 }
@@ -136,15 +134,15 @@ impl Serialize for Capabilities {
136134 }
137135 for filter in & self . read {
138136 let name = match filter {
139- EventFilter :: MessageLike ( _) => READ_EVENT ,
140- EventFilter :: State ( _) => READ_STATE ,
137+ Filter :: MessageLike ( _) => READ_EVENT ,
138+ Filter :: State ( _) => READ_STATE ,
141139 } ;
142140 seq. serialize_element ( & format ! ( "{name}:{}" , PrintEventFilter ( filter) ) ) ?;
143141 }
144142 for filter in & self . send {
145143 let name = match filter {
146- EventFilter :: MessageLike ( _) => SEND_EVENT ,
147- EventFilter :: State ( _) => SEND_STATE ,
144+ Filter :: MessageLike ( _) => SEND_EVENT ,
145+ Filter :: State ( _) => SEND_STATE ,
148146 } ;
149147 seq. serialize_element ( & format ! ( "{name}:{}" , PrintEventFilter ( filter) ) ) ?;
150148 }
@@ -162,8 +160,8 @@ impl<'de> Deserialize<'de> for Capabilities {
162160 RequiresClient ,
163161 UpdateDelayedEvent ,
164162 SendDelayedEvent ,
165- Read ( EventFilter ) ,
166- Send ( EventFilter ) ,
163+ Read ( Filter ) ,
164+ Send ( Filter ) ,
167165 Unknown ,
168166 }
169167
@@ -184,17 +182,17 @@ impl<'de> Deserialize<'de> for Capabilities {
184182 }
185183
186184 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 (
188186 parse_message_event_filter ( filter_s) ,
189187 ) ) ) ,
190- Some ( ( SEND_EVENT , filter_s) ) => Ok ( Permission :: Send ( EventFilter :: MessageLike (
188+ Some ( ( SEND_EVENT , filter_s) ) => Ok ( Permission :: Send ( Filter :: MessageLike (
191189 parse_message_event_filter ( filter_s) ,
192190 ) ) ) ,
193191 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) ) ) )
195193 }
196194 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) ) ) )
198196 }
199197 _ => {
200198 debug ! ( "Unknown capability `{s}`" ) ;
@@ -272,19 +270,17 @@ mod tests {
272270 let parsed = serde_json:: from_str :: < Capabilities > ( capabilities_str) . unwrap ( ) ;
273271 let expected = Capabilities {
274272 read : vec ! [
275- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
273+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType (
276274 "org.matrix.rageshake_request" . into( ) ,
277275 ) ) ,
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( ) ) ) ,
282278 ] ,
283279 send : vec ! [
284- EventFilter :: MessageLike ( MessageLikeEventFilter :: WithType (
280+ Filter :: MessageLike ( MessageLikeEventFilter :: WithType (
285281 "org.matrix.rageshake_request" . into( ) ,
286282 ) ) ,
287- EventFilter :: State ( StateEventFilter :: WithTypeAndStateKey (
283+ Filter :: State ( StateEventFilter :: WithTypeAndStateKey (
288284 "org.matrix.msc3401.call.member" . into( ) ,
289285 "@user:matrix.server" . into( ) ,
290286 ) ) ,
@@ -301,20 +297,16 @@ mod tests {
301297 fn serialization_and_deserialization_are_symmetrical ( ) {
302298 let capabilities = Capabilities {
303299 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 (
309303 "org.matrix.msc3401.call.member" . into( ) ,
310304 "@user:matrix.server" . into( ) ,
311305 ) ) ,
312306 ] ,
313307 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 (
318310 "org.matrix.msc3401.call.member" . into( ) ,
319311 "@user:matrix.server" . into( ) ,
320312 ) ) ,
0 commit comments