diff --git a/crates/matrix-sdk/src/widget/machine/driver_req.rs b/crates/matrix-sdk/src/widget/machine/driver_req.rs index 2a4c43689..e11fd93b2 100644 --- a/crates/matrix-sdk/src/widget/machine/driver_req.rs +++ b/crates/matrix-sdk/src/widget/machine/driver_req.rs @@ -220,6 +220,7 @@ pub(crate) struct SendEventRequest { /// Raw content of an event. pub(crate) content: Box, /// Addition 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 b2efbb926..1644cd5c1 100644 --- a/crates/matrix-sdk/src/widget/machine/from_widget.rs +++ b/crates/matrix-sdk/src/widget/machine/from_widget.rs @@ -137,15 +137,16 @@ pub(super) struct ReadEventResponse { pub struct SendEventResponse { /// The room id for the send event. pub 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. Its optional because if its a future one + /// does not get the event_id at this point. pub event_id: Option, /// A token to send/insert the future into the DAG. pub send_token: Option, /// A token to cancel this future. It will never be send if this is called. pub 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. Used to connect + /// multiple futures only one of the connected futures will be sent and + /// inserted into the DAG. pub 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 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 242c9b94a..c0c6b72ae 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/send_event.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/send_event.rs @@ -1,19 +1,16 @@ -use ruma::owned_room_id; +use std::time::Duration; -use crate::widget::machine::{IncomingMessage, WidgetMachine}; +use ruma::{api::client::future::FutureParameters, events::TimelineEventType}; use super::WIDGET_ID; +use crate::widget::machine::{ + from_widget::FromWidgetRequest, + incoming::{IncomingWidgetMessage, IncomingWidgetMessageKind}, +}; #[test] -fn process_send_event() { - let (mut machine, _) = WidgetMachine::new( - WIDGET_ID.to_owned(), - owned_room_id!("!a98sd12bjh:example.org"), - true, - None, - ); - - let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ +fn parse_future_action() { + let raw = json_string!({ "api": "fromWidget", "widgetId": WIDGET_ID, "requestId": "send_event-request-id", @@ -25,6 +22,19 @@ fn process_send_event() { "state_key": "_@abc:example.org_VFKPEKYWMP", "type": "org.matrix.msc3401.call.member", }, - }))); - println!("{:?}", actions); + }); + 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()); + } + } }