Skip to content

Commit 7ecb9d7

Browse files
committed
widget_driver: doc and test changes (review)
1 parent ac87824 commit 7ecb9d7

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

crates/matrix-sdk/src/widget/machine/driver_req.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub(crate) struct SendEventRequest {
219219
pub(crate) state_key: Option<String>,
220220
/// Raw content of an event.
221221
pub(crate) content: Box<RawJsonValue>,
222-
/// Addition send event parameters to send a future
222+
/// Additional send event parameters to send a future
223223
#[serde(flatten)]
224224
pub(crate) future_parameters: Option<FutureParameters>,
225225
}

crates/matrix-sdk/src/widget/machine/from_widget.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
2525
use super::SendEventRequest;
2626
use crate::widget::StateKeySelector;
2727

28-
#[derive(Deserialize)]
28+
#[derive(Deserialize, Debug)]
2929
#[serde(tag = "action", rename_all = "snake_case", content = "data")]
3030
pub(super) enum FromWidgetRequest {
3131
SupportedApiVersions {},
@@ -112,7 +112,7 @@ pub(super) enum ApiVersion {
112112
MSC3846,
113113
}
114114

115-
#[derive(Deserialize)]
115+
#[derive(Deserialize, Debug)]
116116
#[serde(untagged)]
117117
pub(super) enum ReadEventRequest {
118118
ReadStateEvent {
@@ -137,19 +137,19 @@ pub(super) struct ReadEventResponse {
137137
pub(crate) struct SendEventResponse {
138138
/// The room id for the send event.
139139
pub(crate) room_id: Option<OwnedRoomId>,
140-
/// The event id of the send event. Its optional because if its a future one
141-
/// does not get the event_id at this point.
140+
/// The event id of the send event. It's optional because if it's a future,
141+
/// it does not get the event_id at this point.
142142
pub(crate) event_id: Option<OwnedEventId>,
143143
/// A token to send/insert the future into the DAG.
144144
pub(crate) send_token: Option<String>,
145-
/// A token to cancel this future. It will never be send if this is called.
145+
/// A token to cancel this future. It will never be seny if this is called.
146146
pub(crate) cancel_token: Option<String>,
147147
/// The `future_group_id` generated for this future. Used to connect
148-
/// multiple futures only one of the connected futures will be sent and
148+
/// multiple futures. Only one of the connected futures will be sent and
149149
/// inserted into the DAG.
150150
pub(crate) future_group_id: Option<String>,
151151
/// A token used to refresh the timer of the future. This allows
152-
/// to implement heartbeat like capabilities. An event is only sent once
152+
/// to implement heartbeat-like capabilities. An event is only sent once
153153
/// a refresh in the timeout interval is missed.
154154
///
155155
/// If the future does not have a timeout this will be `None`.

crates/matrix-sdk/src/widget/machine/incoming.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub(super) struct IncomingWidgetMessage {
6666
pub(super) kind: IncomingWidgetMessageKind,
6767
}
6868

69+
#[derive(Debug)]
6970
pub(super) enum IncomingWidgetMessageKind {
7071
Request(Raw<FromWidgetRequest>),
7172
Response(ToWidgetResponse),

crates/matrix-sdk/src/widget/machine/tests/send_event.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::time::Duration;
22

3+
use assert_matches2::assert_let;
34
use ruma::{api::client::future::FutureParameters, events::TimelineEventType};
45

56
use super::WIDGET_ID;
@@ -23,18 +24,20 @@ fn parse_future_action() {
2324
"type": "org.matrix.msc3401.call.member",
2425
},
2526
});
26-
if let IncomingWidgetMessageKind::Request(a) =
27-
serde_json::from_str::<IncomingWidgetMessage>(&raw).unwrap().kind
28-
{
29-
if let FromWidgetRequest::SendEvent(b) = a.deserialize().unwrap() {
30-
let FutureParameters::Timeout { timeout, group_id } = b.future_parameters.unwrap()
31-
else {
32-
panic!()
33-
};
34-
assert_eq!(timeout, Duration::from_millis(10000));
35-
assert_eq!(group_id, None);
36-
assert_eq!(b.event_type, TimelineEventType::CallMember);
37-
assert_eq!(b.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned());
38-
}
39-
}
27+
assert_let!(
28+
IncomingWidgetMessageKind::Request(incoming_request) =
29+
serde_json::from_str::<IncomingWidgetMessage>(&raw).unwrap().kind
30+
);
31+
assert_let!(
32+
FromWidgetRequest::SendEvent(send_event_request) = incoming_request.deserialize().unwrap()
33+
);
34+
assert_let!(
35+
FutureParameters::Timeout { timeout, group_id } =
36+
send_event_request.future_parameters.unwrap()
37+
);
38+
39+
assert_eq!(timeout, Duration::from_millis(10000));
40+
assert_eq!(group_id, None);
41+
assert_eq!(send_event_request.event_type, TimelineEventType::CallMember);
42+
assert_eq!(send_event_request.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned());
4043
}

crates/matrix-sdk/src/widget/machine/to_widget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
}
5959
}
6060

61-
#[derive(Deserialize)]
61+
#[derive(Deserialize, Debug)]
6262
#[serde(rename_all = "camelCase")]
6363
pub(super) struct ToWidgetResponse {
6464
/// The action from the original request.

0 commit comments

Comments
 (0)