@@ -18,7 +18,7 @@ use std::marker::PhantomData;
1818
1919use ruma:: {
2020 api:: client:: { account:: request_openid_token, delayed_events:: update_delayed_event} ,
21- events:: AnyTimelineEvent ,
21+ events:: { AnyStateEvent , AnyTimelineEvent } ,
2222 serde:: Raw ,
2323} ;
2424use serde:: Deserialize ;
@@ -43,11 +43,11 @@ pub(crate) enum MatrixDriverRequestData {
4343 /// Get OpenId token for a given request ID.
4444 GetOpenId ,
4545
46- /// Read message event(s) .
47- ReadMessageLikeEvent ( ReadMessageLikeEventRequest ) ,
46+ /// Read events from the timeline .
47+ ReadEvents ( ReadEventsRequest ) ,
4848
49- /// Read state event(s) .
50- ReadStateEvent ( ReadStateEventRequest ) ,
49+ /// Read room state entries .
50+ ReadState ( ReadStateRequest ) ,
5151
5252 /// Send matrix event that corresponds to the given description.
5353 SendEvent ( SendEventRequest ) ,
@@ -152,26 +152,32 @@ impl FromMatrixDriverResponse for request_openid_token::v3::Response {
152152 }
153153}
154154
155- /// Ask the client to read matrix event(s) that corresponds to the given
155+ /// Ask the client to read matrix events that correspond to the given
156156/// description and return a list of events as a response.
157157#[ derive( Clone , Debug ) ]
158- pub ( crate ) struct ReadMessageLikeEventRequest {
158+ pub ( crate ) struct ReadEventsRequest {
159159 /// The event type to read.
160160 // TODO: This wants to be `MessageLikeEventType`` but we need a type which supports `as_str()`
161161 // as soon as ruma supports `as_str()` on `MessageLikeEventType` we can use it here.
162162 pub ( crate ) event_type : String ,
163163
164+ /// The `state_key` to read. If None, this will read events regardless of
165+ /// whether they are state events. If `Some(Any)`, this will only read state
166+ /// events of the given type. If set to a specific state key, this will only
167+ /// read state events of the given type matching that state key.
168+ pub ( crate ) state_key : Option < StateKeySelector > ,
169+
164170 /// The maximum number of events to return.
165171 pub ( crate ) limit : u32 ,
166172}
167173
168- impl From < ReadMessageLikeEventRequest > for MatrixDriverRequestData {
169- fn from ( value : ReadMessageLikeEventRequest ) -> Self {
170- MatrixDriverRequestData :: ReadMessageLikeEvent ( value)
174+ impl From < ReadEventsRequest > for MatrixDriverRequestData {
175+ fn from ( value : ReadEventsRequest ) -> Self {
176+ MatrixDriverRequestData :: ReadEvents ( value)
171177 }
172178}
173179
174- impl MatrixDriverRequest for ReadMessageLikeEventRequest {
180+ impl MatrixDriverRequest for ReadEventsRequest {
175181 type Response = Vec < Raw < AnyTimelineEvent > > ;
176182}
177183
@@ -187,28 +193,40 @@ impl FromMatrixDriverResponse for Vec<Raw<AnyTimelineEvent>> {
187193 }
188194}
189195
190- /// Ask the client to read matrix event(s) that corresponds to the given
191- /// description and return a list of events as a response.
196+ /// Ask the client to read matrix room state entries corresponding to the given
197+ /// description and return a list of state events as a response.
192198#[ derive( Clone , Debug ) ]
193- pub ( crate ) struct ReadStateEventRequest {
199+ pub ( crate ) struct ReadStateRequest {
194200 /// The event type to read.
195201 // TODO: This wants to be `TimelineEventType` but we need a type which supports `as_str()`
196202 // as soon as ruma supports `as_str()` on `TimelineEventType` we can use it here.
197203 pub ( crate ) event_type : String ,
198204
199- /// The `state_key` to read, or `Any` to receive any/all events of the given
200- /// type, regardless of their `state_key`.
205+ /// The `state_key` to read, or `Any` to receive any/all room state entries
206+ /// of the given type, regardless of their `state_key`.
201207 pub ( crate ) state_key : StateKeySelector ,
202208}
203209
204- impl From < ReadStateEventRequest > for MatrixDriverRequestData {
205- fn from ( value : ReadStateEventRequest ) -> Self {
206- MatrixDriverRequestData :: ReadStateEvent ( value)
210+ impl From < ReadStateRequest > for MatrixDriverRequestData {
211+ fn from ( value : ReadStateRequest ) -> Self {
212+ MatrixDriverRequestData :: ReadState ( value)
207213 }
208214}
209215
210- impl MatrixDriverRequest for ReadStateEventRequest {
211- type Response = Vec < Raw < AnyTimelineEvent > > ;
216+ impl MatrixDriverRequest for ReadStateRequest {
217+ type Response = Vec < Raw < AnyStateEvent > > ;
218+ }
219+
220+ impl FromMatrixDriverResponse for Vec < Raw < AnyStateEvent > > {
221+ fn from_response ( ev : MatrixDriverResponse ) -> Option < Self > {
222+ match ev {
223+ MatrixDriverResponse :: StateRead ( response) => Some ( response) ,
224+ _ => {
225+ error ! ( "bug in MatrixDriver, received wrong event response" ) ;
226+ None
227+ }
228+ }
229+ }
212230}
213231
214232/// Ask the client to send matrix event that corresponds to the given
0 commit comments