diff --git a/crates/matrix-sdk/src/widget/machine/driver_req.rs b/crates/matrix-sdk/src/widget/machine/driver_req.rs index e11fd93b255..aadea1b46a2 100644 --- a/crates/matrix-sdk/src/widget/machine/driver_req.rs +++ b/crates/matrix-sdk/src/widget/machine/driver_req.rs @@ -219,7 +219,7 @@ pub(crate) struct SendEventRequest { pub(crate) state_key: Option, /// Raw content of an event. pub(crate) content: Box, - /// Addition send event parameters to send a future + /// Additional send event parameters to send a future #[serde(flatten)] pub(crate) future_parameters: Option, } diff --git a/crates/matrix-sdk/src/widget/machine/from_widget.rs b/crates/matrix-sdk/src/widget/machine/from_widget.rs index 4aa383c3dfa..e592469c883 100644 --- a/crates/matrix-sdk/src/widget/machine/from_widget.rs +++ b/crates/matrix-sdk/src/widget/machine/from_widget.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use super::SendEventRequest; use crate::widget::StateKeySelector; -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(tag = "action", rename_all = "snake_case", content = "data")] pub(super) enum FromWidgetRequest { SupportedApiVersions {}, @@ -112,7 +112,7 @@ pub(super) enum ApiVersion { MSC3846, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(untagged)] pub(super) enum ReadEventRequest { ReadStateEvent { @@ -137,19 +137,20 @@ pub(super) struct ReadEventResponse { pub(crate) struct SendEventResponse { /// The room id for the send event. pub(crate) room_id: Option, - /// The event id of the send event. Its optional because if its a future one - /// does not get the event_id at this point. + /// The event id of the send event. It's optional because if it's a future + /// event, it does not get the event_id at this point. pub(crate) event_id: Option, /// A token to send/insert the future into the DAG. pub(crate) send_token: Option, - /// A token to cancel this future. It will never be send if this is called. + /// A token to cancel this future event. It will never be seny if this is + /// called. pub(crate) cancel_token: Option, - /// The `future_group_id` generated for this future. Used to connect - /// multiple futures only one of the connected futures will be sent and - /// inserted into the DAG. + /// The `future_group_id` generated for this future event. Used to connect + /// multiple future events. Only one of the connected future event will be + /// sent and inserted into the DAG. pub(crate) future_group_id: Option, /// A token used to refresh the timer of the future. This allows - /// to implement heartbeat like capabilities. An event is only sent once + /// to implement heartbeat-like capabilities. An event is only sent once /// a refresh in the timeout interval is missed. /// /// If the future does not have a timeout this will be `None`. diff --git a/crates/matrix-sdk/src/widget/machine/incoming.rs b/crates/matrix-sdk/src/widget/machine/incoming.rs index 661efae29a2..db9d8e1248f 100644 --- a/crates/matrix-sdk/src/widget/machine/incoming.rs +++ b/crates/matrix-sdk/src/widget/machine/incoming.rs @@ -66,6 +66,7 @@ pub(super) struct IncomingWidgetMessage { pub(super) kind: IncomingWidgetMessageKind, } +#[derive(Debug)] pub(super) enum IncomingWidgetMessageKind { Request(Raw), Response(ToWidgetResponse), diff --git a/crates/matrix-sdk/src/widget/machine/tests/send_event.rs b/crates/matrix-sdk/src/widget/machine/tests/send_event.rs index c0c6b72aeb2..8467b7a726f 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/send_event.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/send_event.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use assert_matches2::assert_let; use ruma::{api::client::future::FutureParameters, events::TimelineEventType}; use super::WIDGET_ID; @@ -23,18 +24,20 @@ fn parse_future_action() { "type": "org.matrix.msc3401.call.member", }, }); - if let IncomingWidgetMessageKind::Request(a) = - serde_json::from_str::(&raw).unwrap().kind - { - if let FromWidgetRequest::SendEvent(b) = a.deserialize().unwrap() { - let FutureParameters::Timeout { timeout, group_id } = b.future_parameters.unwrap() - else { - panic!() - }; - assert_eq!(timeout, Duration::from_millis(10000)); - assert_eq!(group_id, None); - assert_eq!(b.event_type, TimelineEventType::CallMember); - assert_eq!(b.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned()); - } - } + assert_let!( + IncomingWidgetMessageKind::Request(incoming_request) = + serde_json::from_str::(&raw).unwrap().kind + ); + assert_let!( + FromWidgetRequest::SendEvent(send_event_request) = incoming_request.deserialize().unwrap() + ); + assert_let!( + FutureParameters::Timeout { timeout, group_id } = + send_event_request.future_parameters.unwrap() + ); + + assert_eq!(timeout, Duration::from_millis(10000)); + assert_eq!(group_id, None); + assert_eq!(send_event_request.event_type, TimelineEventType::CallMember); + assert_eq!(send_event_request.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned()); } diff --git a/crates/matrix-sdk/src/widget/machine/to_widget.rs b/crates/matrix-sdk/src/widget/machine/to_widget.rs index f002077c36e..5315ffb5850 100644 --- a/crates/matrix-sdk/src/widget/machine/to_widget.rs +++ b/crates/matrix-sdk/src/widget/machine/to_widget.rs @@ -58,7 +58,7 @@ where } } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub(super) struct ToWidgetResponse { /// The action from the original request.