Skip to content

Commit

Permalink
Fix widget action format and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Jul 4, 2024
1 parent 0506014 commit 1d3b270
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions crates/matrix-sdk/src/widget/machine/driver_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ pub(crate) struct SendEventRequest {
/// Raw content of an event.
pub(crate) content: Box<RawJsonValue>,
/// Addition send event parameters to send a future
#[serde(flatten)]
pub(crate) future_parameters: Option<FutureParameters>,
}

Expand Down
9 changes: 5 additions & 4 deletions crates/matrix-sdk/src/widget/machine/from_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ pub(super) struct ReadEventResponse {
pub struct SendEventResponse {
/// The room id for the send event.
pub room_id: Option<OwnedRoomId>,
/// 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<OwnedEventId>,
/// A token to send/insert the future into the DAG.
pub send_token: Option<String>,
/// A token to cancel this future. It will never be send if this is called.
pub cancel_token: Option<String>,
/// 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<String>,
/// A token used to refresh the timer of the future. This allows
/// to implement heartbeat like capabilities. An event is only sent once
Expand Down
36 changes: 23 additions & 13 deletions crates/matrix-sdk/src/widget/machine/tests/send_event.rs
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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::<IncomingWidgetMessage>(&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());
}
}
}

0 comments on commit 1d3b270

Please sign in to comment.