mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 16:04:13 -04:00
widget-driver: Fix widget action format and add test.
This commit is contained in:
@@ -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>,
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user