Skip to content

Commit 1d3b270

Browse files
committed
Fix widget action format and add test
1 parent 0506014 commit 1d3b270

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

crates/matrix-sdk/src/widget/machine/driver_req.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ pub(crate) struct SendEventRequest {
220220
/// Raw content of an event.
221221
pub(crate) content: Box<RawJsonValue>,
222222
/// Addition send event parameters to send a future
223+
#[serde(flatten)]
223224
pub(crate) future_parameters: Option<FutureParameters>,
224225
}
225226

crates/matrix-sdk/src/widget/machine/from_widget.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,16 @@ pub(super) struct ReadEventResponse {
137137
pub struct SendEventResponse {
138138
/// The room id for the send event.
139139
pub room_id: Option<OwnedRoomId>,
140-
/// The event id of the send event. Its optional because if its a future one does not get
141-
/// the event_id at this point.
140+
/// The event id of the send event. Its optional because if its a future one
141+
/// does not get the event_id at this point.
142142
pub event_id: Option<OwnedEventId>,
143143
/// A token to send/insert the future into the DAG.
144144
pub send_token: Option<String>,
145145
/// A token to cancel this future. It will never be send if this is called.
146146
pub cancel_token: Option<String>,
147-
/// The `future_group_id` generated for this future. Used to connect multiple futures
148-
/// only one of the connected futures will be sent and inserted into the DAG.
147+
/// The `future_group_id` generated for this future. Used to connect
148+
/// multiple futures only one of the connected futures will be sent and
149+
/// inserted into the DAG.
149150
pub future_group_id: Option<String>,
150151
/// A token used to refresh the timer of the future. This allows
151152
/// to implement heartbeat like capabilities. An event is only sent once
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
use ruma::owned_room_id;
1+
use std::time::Duration;
22

3-
use crate::widget::machine::{IncomingMessage, WidgetMachine};
3+
use ruma::{api::client::future::FutureParameters, events::TimelineEventType};
44

55
use super::WIDGET_ID;
6+
use crate::widget::machine::{
7+
from_widget::FromWidgetRequest,
8+
incoming::{IncomingWidgetMessage, IncomingWidgetMessageKind},
9+
};
610

711
#[test]
8-
fn process_send_event() {
9-
let (mut machine, _) = WidgetMachine::new(
10-
WIDGET_ID.to_owned(),
11-
owned_room_id!("!a98sd12bjh:example.org"),
12-
true,
13-
None,
14-
);
15-
16-
let actions = machine.process(IncomingMessage::WidgetMessage(json_string!({
12+
fn parse_future_action() {
13+
let raw = json_string!({
1714
"api": "fromWidget",
1815
"widgetId": WIDGET_ID,
1916
"requestId": "send_event-request-id",
@@ -25,6 +22,19 @@ fn process_send_event() {
2522
"state_key": "_@abc:example.org_VFKPEKYWMP",
2623
"type": "org.matrix.msc3401.call.member",
2724
},
28-
})));
29-
println!("{:?}", actions);
25+
});
26+
if let IncomingWidgetMessageKind::Request(a) =
27+
serde_json::from_str::<IncomingWidgetMessage>(&raw).unwrap().kind
28+
{
29+
if let FromWidgetRequest::SendEvent(b) = a.deserialize().unwrap() {
30+
let FutureParameters::Timeout { timeout, group_id } = b.future_parameters.unwrap()
31+
else {
32+
panic!()
33+
};
34+
assert_eq!(timeout, Duration::from_millis(10000));
35+
assert_eq!(group_id, None);
36+
assert_eq!(b.event_type, TimelineEventType::CallMember);
37+
assert_eq!(b.state_key.unwrap(), "_@abc:example.org_VFKPEKYWMP".to_owned());
38+
}
39+
}
3040
}

0 commit comments

Comments
 (0)