mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
refactor(widget): get rid of unused limits parameter when constructing a WidgetMachine
This commit is contained in:
@@ -132,12 +132,9 @@ impl WidgetMachine {
|
||||
widget_id: String,
|
||||
room_id: OwnedRoomId,
|
||||
init_on_content_load: bool,
|
||||
limits: Option<RequestLimits>,
|
||||
) -> (Self, Vec<Action>) {
|
||||
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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -130,13 +130,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(),
|
||||
@@ -147,6 +150,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(),
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user