@@ -21,7 +21,7 @@ use ruma::{
2121 account:: request_openid_token, delayed_events:: update_delayed_event,
2222 to_device:: send_event_to_device,
2323 } ,
24- events:: { AnyTimelineEvent , AnyToDeviceEventContent } ,
24+ events:: { AnyStateEvent , AnyTimelineEvent , AnyToDeviceEventContent } ,
2525 serde:: Raw ,
2626 to_device:: DeviceIdOrAllDevices ,
2727 OwnedUserId ,
@@ -48,11 +48,11 @@ pub(crate) enum MatrixDriverRequestData {
4848 /// Get OpenId token for a given request ID.
4949 GetOpenId ,
5050
51- /// Read message event(s) .
52- ReadMessageLikeEvent ( ReadMessageLikeEventRequest ) ,
51+ /// Read events from the timeline .
52+ ReadEvents ( ReadEventsRequest ) ,
5353
54- /// Read state event(s) .
55- ReadStateEvent ( ReadStateEventRequest ) ,
54+ /// Read room state entries .
55+ ReadState ( ReadStateRequest ) ,
5656
5757 /// Send Matrix event that corresponds to the given description.
5858 SendEvent ( SendEventRequest ) ,
@@ -170,26 +170,32 @@ impl FromMatrixDriverResponse for request_openid_token::v3::Response {
170170 }
171171}
172172
173- /// Ask the client to read Matrix event(s) that corresponds to the given
173+ /// Ask the client to read Matrix events that correspond to the given
174174/// description and return a list of events as a response.
175175#[ derive( Clone , Debug ) ]
176- pub ( crate ) struct ReadMessageLikeEventRequest {
176+ pub ( crate ) struct ReadEventsRequest {
177177 /// The event type to read.
178178 // TODO: This wants to be `MessageLikeEventType`` but we need a type which supports `as_str()`
179179 // as soon as ruma supports `as_str()` on `MessageLikeEventType` we can use it here.
180180 pub ( crate ) event_type : String ,
181181
182+ /// The `state_key` to read. If None, this will read events regardless of
183+ /// whether they are state events. If `Some(Any)`, this will only read state
184+ /// events of the given type. If set to a specific state key, this will only
185+ /// read state events of the given type matching that state key.
186+ pub ( crate ) state_key : Option < StateKeySelector > ,
187+
182188 /// The maximum number of events to return.
183189 pub ( crate ) limit : u32 ,
184190}
185191
186- impl From < ReadMessageLikeEventRequest > for MatrixDriverRequestData {
187- fn from ( value : ReadMessageLikeEventRequest ) -> Self {
188- MatrixDriverRequestData :: ReadMessageLikeEvent ( value)
192+ impl From < ReadEventsRequest > for MatrixDriverRequestData {
193+ fn from ( value : ReadEventsRequest ) -> Self {
194+ MatrixDriverRequestData :: ReadEvents ( value)
189195 }
190196}
191197
192- impl MatrixDriverRequest for ReadMessageLikeEventRequest {
198+ impl MatrixDriverRequest for ReadEventsRequest {
193199 type Response = Vec < Raw < AnyTimelineEvent > > ;
194200}
195201
@@ -205,28 +211,40 @@ impl FromMatrixDriverResponse for Vec<Raw<AnyTimelineEvent>> {
205211 }
206212}
207213
208- /// Ask the client to read Matrix event(s) that corresponds to the given
209- /// description and return a list of events as a response.
214+ /// Ask the client to read Matrix room state entries corresponding to the given
215+ /// description and return a list of state events as a response.
210216#[ derive( Clone , Debug ) ]
211- pub ( crate ) struct ReadStateEventRequest {
217+ pub ( crate ) struct ReadStateRequest {
212218 /// The event type to read.
213219 // TODO: This wants to be `TimelineEventType` but we need a type which supports `as_str()`
214220 // as soon as ruma supports `as_str()` on `TimelineEventType` we can use it here.
215221 pub ( crate ) event_type : String ,
216222
217- /// The `state_key` to read, or `Any` to receive any/all events of the given
218- /// type, regardless of their `state_key`.
223+ /// The `state_key` to read, or `Any` to receive any/all room state entries
224+ /// of the given type, regardless of their `state_key`.
219225 pub ( crate ) state_key : StateKeySelector ,
220226}
221227
222- impl From < ReadStateEventRequest > for MatrixDriverRequestData {
223- fn from ( value : ReadStateEventRequest ) -> Self {
224- MatrixDriverRequestData :: ReadStateEvent ( value)
228+ impl From < ReadStateRequest > for MatrixDriverRequestData {
229+ fn from ( value : ReadStateRequest ) -> Self {
230+ MatrixDriverRequestData :: ReadState ( value)
225231 }
226232}
227233
228- impl MatrixDriverRequest for ReadStateEventRequest {
229- type Response = Vec < Raw < AnyTimelineEvent > > ;
234+ impl MatrixDriverRequest for ReadStateRequest {
235+ type Response = Vec < Raw < AnyStateEvent > > ;
236+ }
237+
238+ impl FromMatrixDriverResponse for Vec < Raw < AnyStateEvent > > {
239+ fn from_response ( ev : MatrixDriverResponse ) -> Option < Self > {
240+ match ev {
241+ MatrixDriverResponse :: StateRead ( response) => Some ( response) ,
242+ _ => {
243+ error ! ( "bug in MatrixDriver, received wrong event response" ) ;
244+ None
245+ }
246+ }
247+ }
230248}
231249
232250/// Ask the client to send Matrix event that corresponds to the given
0 commit comments