diff --git a/Cargo.lock b/Cargo.lock index f262ce7b2c5..69fc376a830 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5060,7 +5060,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "assign", "js_int", @@ -5077,7 +5077,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "as_variant", "assign", @@ -5100,7 +5100,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "as_variant", "base64 0.22.1", @@ -5132,7 +5132,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -5157,7 +5157,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "http 1.1.0", "js_int", @@ -5171,7 +5171,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.2.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "as_variant", "html5ever", @@ -5183,7 +5183,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "js_int", "thiserror", @@ -5192,7 +5192,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "once_cell", "proc-macro-crate", @@ -5207,7 +5207,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://github.com/toger5/ruma?rev=195cc6f57464b541d6ec0e8368c0993b3f62a760#195cc6f57464b541d6ec0e8368c0993b3f62a760" +source = "git+https://github.com/toger5/ruma?rev=2ca7559b306d5aa5e6b7be2629d14c5d685fecb9#2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" dependencies = [ "js_int", "ruma-common", diff --git a/Cargo.toml b/Cargo.toml index 515156f39cf..2b12464d6c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ once_cell = "1.16.0" pin-project-lite = "0.2.9" rand = "0.8.5" reqwest = { version = "0.12.4", default-features = false } -ruma = { git = "https://github.com/toger5/ruma", rev = "195cc6f57464b541d6ec0e8368c0993b3f62a760", features = [ +ruma = { git = "https://github.com/toger5/ruma", rev = "2ca7559b306d5aa5e6b7be2629d14c5d685fecb9", features = [ "client-api-c", "compat-upload-signatures", "compat-user-id", @@ -59,7 +59,7 @@ ruma = { git = "https://github.com/toger5/ruma", rev = "195cc6f57464b541d6ec0e83 "unstable-msc4075", "unstable-msc4140", ] } -ruma-common = { git = "https://github.com/toger5/ruma", rev = "195cc6f57464b541d6ec0e8368c0993b3f62a760" } +ruma-common = { git = "https://github.com/toger5/ruma", rev = "2ca7559b306d5aa5e6b7be2629d14c5d685fecb9" } serde = "1.0.151" serde_html_form = "0.2.0" serde_json = "1.0.91" diff --git a/crates/matrix-sdk/src/widget/capabilities.rs b/crates/matrix-sdk/src/widget/capabilities.rs index d9497f77ca4..e8ebc16bf2a 100644 --- a/crates/matrix-sdk/src/widget/capabilities.rs +++ b/crates/matrix-sdk/src/widget/capabilities.rs @@ -250,6 +250,16 @@ mod tests { use super::*; + #[test] + fn deserialization_of_no_capabilities() { + let capabilities_str = r#"[]"#; + + let parsed = serde_json::from_str::(capabilities_str).unwrap(); + let expected = Capabilities::default(); + + assert_eq!(parsed, expected); + } + #[test] fn deserialization_of_capabilities() { let capabilities_str = r#"[ @@ -260,7 +270,8 @@ mod tests { "org.matrix.msc2762.receive.state_event:org.matrix.msc3401.call.member", "org.matrix.msc2762.send.event:org.matrix.rageshake_request", "org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@user:matrix.server", - "org.matrix.msc4140.send.delayed_event" + "org.matrix.msc4157.send.delayed_event", + "org.matrix.msc4157.update.delayed_event" ]"#; let parsed = serde_json::from_str::(capabilities_str).unwrap(); @@ -285,7 +296,7 @@ mod tests { ], requires_client: true, update_future_event: true, - send_future_event: false, + send_future_event: true, }; assert_eq!(parsed, expected); diff --git a/crates/matrix-sdk/src/widget/machine/driver_req.rs b/crates/matrix-sdk/src/widget/machine/driver_req.rs index 2641f9f5097..4b54034a457 100644 --- a/crates/matrix-sdk/src/widget/machine/driver_req.rs +++ b/crates/matrix-sdk/src/widget/machine/driver_req.rs @@ -17,14 +17,11 @@ use std::marker::PhantomData; use ruma::{ - api::client::{ - account::request_openid_token, - future::{update_future, FutureParameters}, - }, + api::client::{account::request_openid_token, delayed_events::update_delayed_event}, events::{AnyTimelineEvent, MessageLikeEventType, StateEventType, TimelineEventType}, serde::Raw, }; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use serde_json::value::RawValue as RawJsonValue; use tracing::error; @@ -216,7 +213,8 @@ impl MatrixDriverRequest for ReadStateEventRequest { } /// Ask the client to send matrix event that corresponds to the given -/// description and return an event ID as a response. +/// description and returns an event ID (or a delay_id, +/// see delayed events https://github.com/matrix-org/matrix-spec-proposals/pull/4140) as a response. #[derive(Clone, Debug, Deserialize)] pub(crate) struct SendEventRequest { /// The type of the event. @@ -226,9 +224,11 @@ 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 event. - #[serde(flatten)] - pub(crate) future_event_parameters: Option, + /// The delay for this request in ms. + /// The widget does not use the `org.matrix.msc4140.delay` unstable prefix. + /// It uses just an optional `delay` property. If provided the response will contain a + /// delay_id instead of a event_id. + pub(crate) delay: Option, } impl From for MatrixDriverRequestData { @@ -254,9 +254,10 @@ impl FromMatrixDriverResponse for SendEventResponse { } /// Ask the client to send a UpdateFuture request with the given `future_id` and `action`. -#[derive(Clone, Debug, Deserialize)] +#[derive(Deserialize, Debug)] pub(crate) struct UpdateFutureRequest { - pub(crate) action: update_future::unstable::UpdateAction, + pub(crate) action: update_delayed_event::unstable::UpdateAction, + #[serde(rename = "delay_id")] pub(crate) future_id: String, } @@ -267,10 +268,10 @@ impl From for MatrixDriverRequestData { } impl MatrixDriverRequest for UpdateFutureRequest { - type Response = update_future::unstable::Response; + type Response = update_delayed_event::unstable::Response; } -impl FromMatrixDriverResponse for update_future::unstable::Response { +impl FromMatrixDriverResponse for update_delayed_event::unstable::Response { fn from_response(ev: MatrixDriverResponse) -> Option { match ev { MatrixDriverResponse::MatrixFutureUpdate(response) => Some(response), diff --git a/crates/matrix-sdk/src/widget/machine/from_widget.rs b/crates/matrix-sdk/src/widget/machine/from_widget.rs index 1608981df2c..355b632505e 100644 --- a/crates/matrix-sdk/src/widget/machine/from_widget.rs +++ b/crates/matrix-sdk/src/widget/machine/from_widget.rs @@ -15,14 +15,16 @@ use std::fmt; use ruma::{ - api::client::future::{send_future_message_event, send_future_state_event, update_future}, + api::client::delayed_events::{ + delayed_message_event, delayed_state_event, update_delayed_event, + }, events::{AnyTimelineEvent, MessageLikeEventType, StateEventType}, serde::Raw, OwnedEventId, OwnedRoomId, }; use serde::{Deserialize, Serialize}; -use super::SendEventRequest; +use super::{SendEventRequest, UpdateFutureRequest}; use crate::widget::StateKeySelector; #[derive(Deserialize, Debug)] @@ -35,7 +37,7 @@ pub(super) enum FromWidgetRequest { #[serde(rename = "org.matrix.msc2876.read_events")] ReadEvent(ReadEventRequest), SendEvent(SendEventRequest), - #[serde(rename = "org.matrix.msc4157.update_delayed_events")] + #[serde(rename = "org.matrix.msc4157.update_delayed_event")] FutureUpdate(UpdateFutureRequest), } @@ -157,24 +159,24 @@ impl SendEventResponse { } } -impl From for SendEventResponse { - fn from(val: send_future_message_event::unstable::Response) -> Self { - SendEventResponse { room_id: None, event_id: None, future_id: Some(val.future_id) } +impl From for SendEventResponse { + fn from(val: delayed_message_event::unstable::Response) -> Self { + SendEventResponse { room_id: None, event_id: None, future_id: Some(val.delay_id) } } } -impl From for SendEventResponse { - fn from(val: send_future_state_event::unstable::Response) -> Self { - SendEventResponse { room_id: None, event_id: None, future_id: Some(val.future_id) } +impl From for SendEventResponse { + fn from(val: delayed_state_event::unstable::Response) -> Self { + SendEventResponse { room_id: None, event_id: None, future_id: Some(val.delay_id) } } } -/// Widget request for updating Future Events. -#[derive(Serialize, Deserialize, Debug)] -pub(crate) struct UpdateFutureRequest { - /// The update action. - pub(crate) action: update_future::unstable::UpdateAction, - /// The future id that should be updated with this action. - #[serde(rename = "delay_id")] - pub(crate) future_id: String, +// /// A wrapper type for the empty okay response form [`update_delayed_event`](update_delayed_event::unstable::Response) +// /// which derives Serialize. +#[derive(Serialize, Debug)] +pub(crate) struct UpdateFutureResponse {} +impl From for UpdateFutureResponse { + fn from(_: update_delayed_event::unstable::Response) -> Self { + Self {} + } } diff --git a/crates/matrix-sdk/src/widget/machine/incoming.rs b/crates/matrix-sdk/src/widget/machine/incoming.rs index 039068f76ee..a78ab91d243 100644 --- a/crates/matrix-sdk/src/widget/machine/incoming.rs +++ b/crates/matrix-sdk/src/widget/machine/incoming.rs @@ -13,7 +13,7 @@ // limitations under the License. use ruma::{ - api::client::{account::request_openid_token, future::update_future}, + api::client::{account::request_openid_token, delayed_events}, events::AnyTimelineEvent, serde::Raw, }; @@ -62,7 +62,7 @@ pub(crate) enum MatrixDriverResponse { /// Client sent some matrix event. The response contains the event ID. /// A response to an `Action::SendMatrixEvent` command. MatrixEventSent(SendEventResponse), - MatrixFutureUpdate(update_future::unstable::Response), + MatrixFutureUpdate(delayed_events::update_delayed_event::unstable::Response), } pub(super) struct IncomingWidgetMessage { diff --git a/crates/matrix-sdk/src/widget/machine/mod.rs b/crates/matrix-sdk/src/widget/machine/mod.rs index 9939aa31b26..992c768dc84 100644 --- a/crates/matrix-sdk/src/widget/machine/mod.rs +++ b/crates/matrix-sdk/src/widget/machine/mod.rs @@ -19,6 +19,7 @@ use std::{fmt, iter, time::Duration}; use driver_req::UpdateFutureRequest; +use from_widget::UpdateFutureResponse; use indexmap::IndexMap; use ruma::{ serde::{JsonObject, Raw}, @@ -268,7 +269,11 @@ impl WidgetMachine { future_id: req.future_id, }); request.then(|res, machine| { - vec![machine.send_from_widget_result_response(raw_request, res)] + vec![machine.send_from_widget_result_response( + raw_request, + // This is mapped to another type because the update_delay_event::Response does not impl Serialize + res.map(Into::::into), + )] }); request_action.map(|a| vec![a]).unwrap_or_default() } @@ -365,7 +370,7 @@ impl WidgetMachine { Default::default() }), }; - if !capabilities.send_future_event && request.future_event_parameters.is_some() { + if !capabilities.send_future_event && request.delay.is_some() { return Some(self.send_from_widget_error_response( raw_request, format!("Not allowed: missing the {} capability.", capabilities::SEND_FUTURE_EVENT), 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 102beab4582..3e5a69c6d43 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/send_event.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/send_event.rs @@ -1,7 +1,5 @@ -use std::time::Duration; - use assert_matches2::assert_let; -use ruma::{api::client::future::FutureParameters, events::TimelineEventType}; +use ruma::events::TimelineEventType; use super::WIDGET_ID; use crate::widget::machine::{ @@ -18,7 +16,7 @@ fn parse_future_event_widget_action() { "action": "send_event", "data": { "content": {}, - "future_timeout": 10000, + "delay": 10000, "room_id": "!rXAYvblqYaGiJmeRdR:matrix.org", "state_key": "_@abc:example.org_VFKPEKYWMP", "type": "org.matrix.msc3401.call.member", @@ -31,13 +29,9 @@ fn parse_future_event_widget_action() { assert_let!( FromWidgetRequest::SendEvent(send_event_request) = incoming_request.deserialize().unwrap() ); - assert_let!( - FutureParameters::Timeout { timeout, future_parent_id } = - send_event_request.future_event_parameters.unwrap() - ); + assert_let!(delay = send_event_request.delay.unwrap()); - assert_eq!(timeout, Duration::from_millis(10000)); - assert_eq!(future_parent_id, None); + assert_eq!(delay, 10000); 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/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index b01719913b3..9b3fbabc1f9 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -21,8 +21,8 @@ use matrix_sdk_base::deserialized_responses::RawAnySyncOrStrippedState; use ruma::{ api::client::{ account::request_openid_token::v3::{Request as OpenIdRequest, Response as OpenIdResponse}, + delayed_events::{self, update_delayed_event::unstable::UpdateAction}, filter::RoomEventFilter, - future::{self, update_future::unstable::UpdateAction}, }, assign, events::{ @@ -113,7 +113,7 @@ impl MatrixDriver { event_type: TimelineEventType, state_key: Option, content: Box, - future_event_parameters: Option, + future_event_parameters: Option, ) -> Result { let type_str = event_type.to_string(); Ok(match (state_key, future_event_parameters) { @@ -124,7 +124,7 @@ impl MatrixDriver { self.room.send_state_event_raw(&type_str, &key, content).await?.event_id, ), (None, Some(future_event_parameters)) => { - let r = future::send_future_message_event::unstable::Request::new_raw( + let r = delayed_events::delayed_message_event::unstable::Request::new_raw( self.room.room_id().to_owned(), TransactionId::new(), MessageLikeEventType::from(type_str), @@ -134,7 +134,7 @@ impl MatrixDriver { self.room.client.send(r, None).await.map(|r| r.into())? } (Some(key), Some(future_event_parameters)) => { - let r = future::send_future_state_event::unstable::Request::new_raw( + let r = delayed_events::delayed_state_event::unstable::Request::new_raw( self.room.room_id().to_owned(), key, StateEventType::from(type_str), @@ -153,8 +153,8 @@ impl MatrixDriver { &self, future_id: String, action: UpdateAction, - ) -> HttpResult { - let r = future::update_future::unstable::Request::new(future_id, action); + ) -> HttpResult { + let r = delayed_events::update_delayed_event::unstable::Request::new(future_id, action); self.room.client.send(r, None).await } diff --git a/crates/matrix-sdk/src/widget/mod.rs b/crates/matrix-sdk/src/widget/mod.rs index 20207eb9b37..f7c4914a94c 100644 --- a/crates/matrix-sdk/src/widget/mod.rs +++ b/crates/matrix-sdk/src/widget/mod.rs @@ -14,9 +14,10 @@ //! Widget API implementation. -use std::fmt; +use std::{fmt, time::Duration}; use async_channel::{Receiver, Sender}; +use ruma::api::client::delayed_events::DelayParameters; use serde::de::{self, Deserialize, Deserializer, Visitor}; use tokio::sync::mpsc::{unbounded_channel, UnboundedSender}; use tokio_util::sync::{CancellationToken, DropGuard}; @@ -225,14 +226,18 @@ impl ProcessingContext { .map_err(|e| e.to_string()), MatrixDriverRequestData::SendMatrixEvent(req) => { - let SendEventRequest { - event_type, - state_key, - content, - future_event_parameters, - } = req; + let SendEventRequest { event_type, state_key, content, delay } = req; self.matrix_driver - .send(event_type, state_key, content, future_event_parameters) + .send( + event_type, + state_key, + content, + // The widget api action does not use the unstable prefix: `org.matrix.msc4140.delay` + // so we cannot use the `DelayParameters` here and need to convert manually. + delay.map(|d| DelayParameters::Timeout { + timeout: Duration::from_millis(d), + }), + ) .await .map(MatrixDriverResponse::MatrixEventSent) .map_err(|e: crate::Error| e.to_string()) @@ -241,7 +246,7 @@ impl ProcessingContext { .matrix_driver .update_future(req.future_id, req.action) .await - .map(|r| MatrixDriverResponse::MatrixFutureUpdate(r)) + .map(|r| MatrixDriverResponse::MatrixFutureUpdate(r.into())) .map_err(|e: HttpError| e.to_string()), }; diff --git a/crates/matrix-sdk/tests/integration/widget.rs b/crates/matrix-sdk/tests/integration/widget.rs index fc6a62a3c0b..058e6559a85 100644 --- a/crates/matrix-sdk/tests/integration/widget.rs +++ b/crates/matrix-sdk/tests/integration/widget.rs @@ -604,13 +604,17 @@ async fn send_room_name() { 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"])) - .await; + negotiate_capabilities( + &driver_handle, + json!([ + "org.matrix.msc4157.send.delayed_event", + "org.matrix.msc2762.send.event:m.room.message" + ]), + ) + .await; Mock::given(method("PUT")) - .and(path_regex( - r"^/_matrix/client/unstable/org.matrix.msc4140/rooms/.*/send/m.room.message/.*$", - )) + .and(path_regex(r"^/_matrix/client/v3/rooms/.*/send/m.room.message/.*$")) .respond_with(ResponseTemplate::new(200).set_body_json(json!({ "delay_id": "1234", }))) @@ -637,8 +641,8 @@ async fn send_future_room_message_event() { let msg = recv_message(&driver_handle).await; assert_eq!(msg["api"], "fromWidget"); assert_eq!(msg["action"], "send_event"); - let future_id = msg["response"]["delay_id"].as_str().unwrap(); - assert_eq!(future_id, "1234"); + let delay_id = msg["response"]["delay_id"].as_str().unwrap(); + assert_eq!(delay_id, "1234"); // Make sure the event-sending endpoint was hit exactly once mock_server.verify().await; @@ -650,14 +654,15 @@ async fn send_future_state_event() { negotiate_capabilities( &driver_handle, - json!(["org.matrix.msc2762.send.state_event:m.room.name#"]), + json!([ + "org.matrix.msc4157.send.delayed_event", + "org.matrix.msc2762.send.state_event:m.room.name#" + ]), ) .await; Mock::given(method("PUT")) - .and(path_regex( - r"^/_matrix/client/unstable/org.matrix.msc4140/rooms/.*/state/m.room.name/?$", - )) + .and(path_regex(r"^/_matrix/client/v3/rooms/.*/state/m.room.name/?$")) .respond_with(ResponseTemplate::new(200).set_body_json(json!({ "delay_id": "1234", }))) @@ -684,7 +689,7 @@ async fn send_future_state_event() { let msg = recv_message(&driver_handle).await; assert_eq!(msg["api"], "fromWidget"); assert_eq!(msg["action"], "send_event"); - let future_id = msg["response"]["future_id"].as_str().unwrap(); + let future_id = msg["response"]["delay_id"].as_str().unwrap(); assert_eq!(future_id, "1234"); // Make sure the event-sending endpoint was hit exactly once @@ -695,44 +700,33 @@ async fn send_future_state_event() { async fn update_future() { let (_, mock_server, driver_handle) = run_test_driver(false).await; - negotiate_capabilities( - &driver_handle, - json!(["org.matrix.msc2762.send.state_event:m.room.name#"]), - ) - .await; + negotiate_capabilities(&driver_handle, json!(["org.matrix.msc4157.update.delayed_event",])) + .await; - Mock::given(method("PUT")) - .and(path_regex( - r"^/_matrix/client/unstable/org.matrix.msc4140/rooms/.*/state/m.room.name/?$", - )) - .respond_with(ResponseTemplate::new(200).set_body_json(json!({ - "delay_id": "1234", - }))) + Mock::given(method("POST")) + .and(path_regex(r"^/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) .expect(1) .mount(&mock_server) .await; send_request( &driver_handle, - "send-room-message", - "send_event", + "send-delay-update-id", + "org.matrix.msc4157.update_delayed_event", json!({ - "type": "m.room.name", - "state_key": "", - "content": { - "name": "Room Name set by Widget", - }, - "delay":1000, + "action":"refresh", + "delay_id": "1234", }), ) .await; - // Receive the response - let msg = recv_message(&driver_handle).await; - assert_eq!(msg["api"], "fromWidget"); - assert_eq!(msg["action"], "send_event"); - let future_id = msg["response"]["delay_id"].as_str().unwrap(); - assert_eq!(future_id, "1234"); + let response = recv_message(&driver_handle).await; + print!("{:?}", response); + assert_eq!(response["api"], "fromWidget"); + assert_eq!(response["action"], "org.matrix.msc4157.update_delayed_event"); + let empty_response = response["response"].clone(); + assert_eq!(empty_response, serde_json::from_str::("{}").unwrap()); // Make sure the event-sending endpoint was hit exactly once mock_server.verify().await;