diff --git a/crates/matrix-sdk/src/widget/machine/mod.rs b/crates/matrix-sdk/src/widget/machine/mod.rs index e7b86075b8..4649dc3efa 100644 --- a/crates/matrix-sdk/src/widget/machine/mod.rs +++ b/crates/matrix-sdk/src/widget/machine/mod.rs @@ -132,12 +132,9 @@ impl WidgetMachine { widget_id: String, room_id: OwnedRoomId, init_on_content_load: bool, - limits: Option, ) -> (Self, Vec) { - let limits = limits.unwrap_or_else(|| RequestLimits { - max_pending_requests: 15, - response_timeout: Duration::from_secs(10), - }); + let limits = + RequestLimits { max_pending_requests: 15, response_timeout: Duration::from_secs(10) }; let mut machine = Self { widget_id, diff --git a/crates/matrix-sdk/src/widget/machine/tests/api_versions.rs b/crates/matrix-sdk/src/widget/machine/tests/api_versions.rs index 9b803e8f8e..c85d9743d0 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/api_versions.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/api_versions.rs @@ -20,13 +20,9 @@ use super::WIDGET_ID; use crate::widget::machine::{Action, IncomingMessage, WidgetMachine}; #[test] -fn get_supported_api_versions() { - let (mut machine, _) = WidgetMachine::new( - WIDGET_ID.to_owned(), - owned_room_id!("!a98sd12bjh:example.org"), - true, - None, - ); +fn test_get_supported_api_versions() { + let (mut machine, _) = + WidgetMachine::new(WIDGET_ID.to_owned(), owned_room_id!("!a98sd12bjh:example.org"), true); let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ "api": "fromWidget", diff --git a/crates/matrix-sdk/src/widget/machine/tests/capabilities.rs b/crates/matrix-sdk/src/widget/machine/tests/capabilities.rs index 3c06da002a..633d788016 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/capabilities.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/capabilities.rs @@ -23,16 +23,16 @@ use crate::widget::machine::{ }; #[test] -fn machine_can_negotiate_capabilities_immediately() { +fn test_machine_can_negotiate_capabilities_immediately() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance(&mut machine, actions, None); } #[test] -fn machine_can_request_capabilities_on_content_load() { +fn test_machine_can_request_capabilities_on_content_load() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, true, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, true); assert!(actions.is_empty()); // Content loaded event processed. @@ -67,9 +67,9 @@ fn machine_can_request_capabilities_on_content_load() { } #[test] -fn capabilities_failure_results_into_empty_capabilities() { +fn test_capabilities_failure_results_into_empty_capabilities() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); // Ask widget to provide desired capabilities. let actions = { diff --git a/crates/matrix-sdk/src/widget/machine/tests/error.rs b/crates/matrix-sdk/src/widget/machine/tests/error.rs index ccce797d47..a9508b0823 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/error.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/error.rs @@ -20,9 +20,9 @@ use super::{capabilities::assert_capabilities_dance, parse_msg, WIDGET_ID}; use crate::widget::machine::{Action, IncomingMessage, WidgetMachine}; #[test] -fn machine_sends_error_for_unknown_request() { +fn test_machine_sends_error_for_unknown_request() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, _) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, true, None); + let (mut machine, _) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, true); let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ "api": "fromWidget", @@ -46,13 +46,9 @@ fn machine_sends_error_for_unknown_request() { } #[test] -fn read_messages_without_capabilities() { - let (mut machine, _) = WidgetMachine::new( - WIDGET_ID.to_owned(), - owned_room_id!("!a98sd12bjh:example.org"), - true, - None, - ); +fn test_read_messages_without_capabilities() { + let (mut machine, _) = + WidgetMachine::new(WIDGET_ID.to_owned(), owned_room_id!("!a98sd12bjh:example.org"), true); let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ "api": "fromWidget", @@ -77,9 +73,9 @@ fn read_messages_without_capabilities() { } #[test] -fn read_request_for_non_allowed_message_like_events() { +fn test_read_request_for_non_allowed_message_like_events() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance(&mut machine, actions, None); let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ @@ -105,9 +101,9 @@ fn read_request_for_non_allowed_message_like_events() { } #[test] -fn read_request_for_non_allowed_state_events() { +fn test_read_request_for_non_allowed_state_events() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance(&mut machine, actions, None); let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({ @@ -134,9 +130,9 @@ fn read_request_for_non_allowed_state_events() { } #[test] -fn send_request_for_non_allowed_state_events() { +fn test_send_request_for_non_allowed_state_events() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance( &mut machine, actions, @@ -166,9 +162,9 @@ fn send_request_for_non_allowed_state_events() { } #[test] -fn send_request_for_non_allowed_message_like_events() { +fn test_send_request_for_non_allowed_message_like_events() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance( &mut machine, actions, @@ -198,9 +194,9 @@ fn send_request_for_non_allowed_message_like_events() { } #[test] -fn read_request_for_message_like_with_disallowed_msg_type_fails() { +fn test_read_request_for_message_like_with_disallowed_msg_type_fails() { let room_id = owned_room_id!("!a98sd12bjh:example.org"); - let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false, None); + let (mut machine, actions) = WidgetMachine::new(WIDGET_ID.to_owned(), room_id, false); assert_capabilities_dance( &mut machine, actions, diff --git a/crates/matrix-sdk/src/widget/machine/tests/openid.rs b/crates/matrix-sdk/src/widget/machine/tests/openid.rs index f5b248b3c0..2aef7f6696 100644 --- a/crates/matrix-sdk/src/widget/machine/tests/openid.rs +++ b/crates/matrix-sdk/src/widget/machine/tests/openid.rs @@ -27,13 +27,9 @@ use crate::widget::machine::{ }; #[test] -fn openid_request_handling_works() { - let (mut machine, _) = WidgetMachine::new( - WIDGET_ID.to_owned(), - owned_room_id!("!a98sd12bjh:example.org"), - true, - None, - ); +fn test_openid_request_handling_works() { + let (mut machine, _) = + WidgetMachine::new(WIDGET_ID.to_owned(), owned_room_id!("!a98sd12bjh:example.org"), true); // Widget requests an open ID token, since we don't have any caching yet, // we reply with a pending response right away. @@ -112,13 +108,9 @@ fn openid_request_handling_works() { } #[test] -fn openid_fail_results_in_response_blocked() { - let (mut machine, _) = WidgetMachine::new( - WIDGET_ID.to_owned(), - owned_room_id!("!a98sd12bjh:example.org"), - true, - None, - ); +fn test_openid_fail_results_in_response_blocked() { + let (mut machine, _) = + WidgetMachine::new(WIDGET_ID.to_owned(), owned_room_id!("!a98sd12bjh:example.org"), true); // Widget requests an open ID token, since we don't have any caching yet, // we reply with a pending response right away. diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index e30e342d60..9518fc514a 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -129,13 +129,16 @@ impl MatrixDriver { self.room.redact(&redacts, None, None).await?.event_id, )); } + Ok(match (state_key, delayed_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(delayed_event_parameters)) => { let r = delayed_events::delayed_message_event::unstable::Request::new_raw( self.room.room_id().to_owned(), @@ -146,6 +149,7 @@ impl MatrixDriver { ); self.room.client.send(r, None).await.map(|r| r.into())? } + (Some(key), Some(delayed_event_parameters)) => { let r = delayed_events::delayed_state_event::unstable::Request::new_raw( self.room.room_id().to_owned(), diff --git a/crates/matrix-sdk/src/widget/mod.rs b/crates/matrix-sdk/src/widget/mod.rs index 74e847f013..c80d0c0db7 100644 --- a/crates/matrix-sdk/src/widget/mod.rs +++ b/crates/matrix-sdk/src/widget/mod.rs @@ -154,7 +154,6 @@ impl WidgetDriver { self.settings.widget_id().to_owned(), room.room_id().to_owned(), self.settings.init_on_content_load(), - None, ); let matrix_driver = MatrixDriver::new(room.clone());