diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index 92236aa2dc..55c9dcefc8 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -35,8 +35,8 @@ Additions: - Add `send_call_notification` and `send_call_notification_if_needed` methods. This allows to implement sending ring events on call start. - The `get_media_content`, `get_media_file` and `get_file` methods of the `Media` api now support the new authenticated media endpoints. -- WidgetDriver: Allow the `"future_timeout"` and `"future_group_id"` fields in the `send_event` widget actions. - As defined in [MSC4157](https://github.com/matrix-org/matrix-spec-proposals/pull/4157) +- WidgetDriver: Support the `"future_timeout"` and `"future_group_id"` fields in the `send_event` widget actions. +This allows to send future events, as defined in [MSC4157](https://github.com/matrix-org/matrix-spec-proposals/pull/4157) # 0.7.0 diff --git a/crates/matrix-sdk/src/widget/machine/driver_req.rs b/crates/matrix-sdk/src/widget/machine/driver_req.rs index aadea1b46a..58b7dd6406 100644 --- a/crates/matrix-sdk/src/widget/machine/driver_req.rs +++ b/crates/matrix-sdk/src/widget/machine/driver_req.rs @@ -219,9 +219,9 @@ pub(crate) struct SendEventRequest { pub(crate) state_key: Option, /// Raw content of an event. pub(crate) content: Box, - /// Additional send event parameters to send a future + /// Additional send event parameters to send a future event. #[serde(flatten)] - pub(crate) future_parameters: Option, + pub(crate) future_event_parameters: Option, } impl From for MatrixDriverRequestData { diff --git a/crates/matrix-sdk/src/widget/machine/from_widget.rs b/crates/matrix-sdk/src/widget/machine/from_widget.rs index e592469c88..12f42b26b1 100644 --- a/crates/matrix-sdk/src/widget/machine/from_widget.rs +++ b/crates/matrix-sdk/src/widget/machine/from_widget.rs @@ -140,20 +140,20 @@ pub(crate) struct SendEventResponse { /// 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. + /// A token to send/insert the future event into the DAG. pub(crate) send_token: Option, - /// A token to cancel this future event. It will never be seny if this is + /// A token to cancel this future event. It will never be sent if this is /// called. pub(crate) cancel_token: Option, /// The `future_group_id` generated for this future event. Used to connect - /// multiple future events. Only one of the connected future event will be + /// multiple future events. Only one of the connected future events 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 + /// A token used to refresh the timer of the future event. This allows /// 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`. + /// If the future event does not have a timeout this will be `None`. pub(crate) refresh_token: Option, } 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 8467b7a726..a29ab3f73a 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/send_event.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/send_event.rs @@ -10,7 +10,7 @@ use crate::widget::machine::{ }; #[test] -fn parse_future_action() { +fn parse_future_event_widget_action() { let raw = json_string!({ "api": "fromWidget", "widgetId": WIDGET_ID, @@ -33,7 +33,7 @@ fn parse_future_action() { ); assert_let!( FutureParameters::Timeout { timeout, group_id } = - send_event_request.future_parameters.unwrap() + send_event_request.future_event_parameters.unwrap() ); assert_eq!(timeout, Duration::from_millis(10000)); diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index 647d58d2df..ce23f2acf8 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -113,32 +113,32 @@ impl MatrixDriver { event_type: TimelineEventType, state_key: Option, content: Box, - future: Option, + future_event_parameters: Option, ) -> Result { let type_str = event_type.to_string(); - Ok(match (state_key, future) { + Ok(match (state_key, future_event_parameters) { (None, None) => SendEventResponse::from_event_id( self.room.send_raw(&type_str, content).await?.event_id, ), (Some(key), None) => SendEventResponse::from_event_id( self.room.send_state_event_raw(&type_str, &key, content).await?.event_id, ), - (None, Some(future)) => { + (None, Some(future_event_parameters)) => { let r = future::send_future_message_event::unstable::Request::new_raw( self.room.room_id().to_owned(), TransactionId::new().to_owned(), MessageLikeEventType::from(type_str), - future, + future_event_parameters, Raw::::from_json(content), ); self.room.client.send(r, None).await.map(|r| r.into())? } - (Some(key), Some(future)) => { + (Some(key), Some(future_event_parameters)) => { let r = future::send_future_state_event::unstable::Request::new_raw( self.room.room_id().to_owned(), key, StateEventType::from(type_str), - future, + future_event_parameters, Raw::::from_json(content), ); self.room.client.send(r, None).await.map(|r| r.into())? diff --git a/crates/matrix-sdk/src/widget/mod.rs b/crates/matrix-sdk/src/widget/mod.rs index b3bc49e93b..96cd60d59d 100644 --- a/crates/matrix-sdk/src/widget/mod.rs +++ b/crates/matrix-sdk/src/widget/mod.rs @@ -225,10 +225,14 @@ impl ProcessingContext { .map_err(|e| e.to_string()), MatrixDriverRequestData::SendMatrixEvent(req) => { - let SendEventRequest { event_type, state_key, content, future_parameters } = - req; + let SendEventRequest { + event_type, + state_key, + content, + future_event_parameters, + } = req; self.matrix_driver - .send(event_type, state_key, content, future_parameters) + .send(event_type, state_key, content, future_event_parameters) .await .map(MatrixDriverResponse::MatrixEventSent) .map_err(|e| e.to_string()) diff --git a/crates/matrix-sdk/tests/integration/widget.rs b/crates/matrix-sdk/tests/integration/widget.rs index 6e14053043..441fdbe88b 100644 --- a/crates/matrix-sdk/tests/integration/widget.rs +++ b/crates/matrix-sdk/tests/integration/widget.rs @@ -601,7 +601,7 @@ async fn send_room_name() { } #[async_test] -async fn send_future_room_message() { +async fn send_future_room_message_event() { let (_, mock_server, driver_handle) = run_test_driver(false).await; negotiate_capabilities(&driver_handle, json!(["org.matrix.msc2762.send.event:m.room.message"])) @@ -654,7 +654,7 @@ async fn send_future_room_message() { } #[async_test] -async fn send_future_state() { +async fn send_future_state_event() { let (_, mock_server, driver_handle) = run_test_driver(false).await; negotiate_capabilities(