Skip to content

Commit

Permalink
widget-driver: rename all mentions of future in the context of futu…
Browse files Browse the repository at this point in the history
…re events.

We need to disambigute future events and rust futures.
  • Loading branch information
toger5 committed Jul 10, 2024
1 parent b2caec3 commit 48c471b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Additions:
- Add `send_call_notification` and `send_call_notification_if_needed` methods. This allows to implement sending ring events on call start.
- The `get_media_content`, `get_media_file` and `get_file` methods of the
`Media` api now support the new authenticated media endpoints.
- WidgetDriver: Allow the `"future_timeout"` and `"future_group_id"` fields in the `send_event` widget actions.
As defined in [MSC4157](https://github.com/matrix-org/matrix-spec-proposals/pull/4157)
- WidgetDriver: Support the `"future_timeout"` and `"future_group_id"` fields in the `send_event` widget actions.
This allows to send future events, as defined in [MSC4157](https://github.com/matrix-org/matrix-spec-proposals/pull/4157)

# 0.7.0

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/widget/machine/driver_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ pub(crate) struct SendEventRequest {
pub(crate) state_key: Option<String>,
/// Raw content of an event.
pub(crate) content: Box<RawJsonValue>,
/// Additional send event parameters to send a future
/// Additional send event parameters to send a future event.
#[serde(flatten)]
pub(crate) future_parameters: Option<FutureParameters>,
pub(crate) future_event_parameters: Option<FutureParameters>,
}

impl From<SendEventRequest> for MatrixDriverRequestData {
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk/src/widget/machine/from_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,20 @@ pub(crate) struct SendEventResponse {
/// The event id of the send event. It's optional because if it's a future
/// event, it does not get the event_id at this point.
pub(crate) event_id: Option<OwnedEventId>,
/// A token to send/insert the future into the DAG.
/// A token to send/insert the future event into the DAG.
pub(crate) send_token: Option<String>,
/// A token to cancel this future event. It will never be seny if this is
/// A token to cancel this future event. It will never be sent if this is
/// called.
pub(crate) cancel_token: Option<String>,
/// The `future_group_id` generated for this future event. Used to connect
/// multiple future events. Only one of the connected future event will be
/// multiple future events. Only one of the connected future events will be
/// sent and inserted into the DAG.
pub(crate) future_group_id: Option<String>,
/// A token used to refresh the timer of the future. This allows
/// A token used to refresh the timer of the future event. This allows
/// to implement heartbeat-like capabilities. An event is only sent once
/// a refresh in the timeout interval is missed.
///
/// If the future does not have a timeout this will be `None`.
/// If the future event does not have a timeout this will be `None`.
pub(crate) refresh_token: Option<String>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/widget/machine/tests/send_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::widget::machine::{
};

#[test]
fn parse_future_action() {
fn parse_future_event_widget_action() {
let raw = json_string!({
"api": "fromWidget",
"widgetId": WIDGET_ID,
Expand All @@ -33,7 +33,7 @@ fn parse_future_action() {
);
assert_let!(
FutureParameters::Timeout { timeout, group_id } =
send_event_request.future_parameters.unwrap()
send_event_request.future_event_parameters.unwrap()
);

assert_eq!(timeout, Duration::from_millis(10000));
Expand Down
12 changes: 6 additions & 6 deletions crates/matrix-sdk/src/widget/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,32 @@ impl MatrixDriver {
event_type: TimelineEventType,
state_key: Option<String>,
content: Box<RawJsonValue>,
future: Option<future::FutureParameters>,
future_event_parameters: Option<future::FutureParameters>,
) -> Result<SendEventResponse> {
let type_str = event_type.to_string();
Ok(match (state_key, future) {
Ok(match (state_key, future_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(future)) => {
(None, Some(future_event_parameters)) => {
let r = future::send_future_message_event::unstable::Request::new_raw(
self.room.room_id().to_owned(),
TransactionId::new().to_owned(),
MessageLikeEventType::from(type_str),
future,
future_event_parameters,
Raw::<AnyMessageLikeEventContent>::from_json(content),
);
self.room.client.send(r, None).await.map(|r| r.into())?
}
(Some(key), Some(future)) => {
(Some(key), Some(future_event_parameters)) => {
let r = future::send_future_state_event::unstable::Request::new_raw(
self.room.room_id().to_owned(),
key,
StateEventType::from(type_str),
future,
future_event_parameters,
Raw::<AnyStateEventContent>::from_json(content),
);
self.room.client.send(r, None).await.map(|r| r.into())?
Expand Down
10 changes: 7 additions & 3 deletions crates/matrix-sdk/src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ impl<T: CapabilitiesProvider> ProcessingContext<T> {
.map_err(|e| e.to_string()),

MatrixDriverRequestData::SendMatrixEvent(req) => {
let SendEventRequest { event_type, state_key, content, future_parameters } =
req;
let SendEventRequest {
event_type,
state_key,
content,
future_event_parameters,
} = req;
self.matrix_driver
.send(event_type, state_key, content, future_parameters)
.send(event_type, state_key, content, future_event_parameters)
.await
.map(MatrixDriverResponse::MatrixEventSent)
.map_err(|e| e.to_string())
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/tests/integration/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ async fn send_room_name() {
}

#[async_test]
async fn send_future_room_message() {
async fn send_future_room_message_event() {
let (_, mock_server, driver_handle) = run_test_driver(false).await;

negotiate_capabilities(&driver_handle, json!(["org.matrix.msc2762.send.event:m.room.message"]))
Expand Down Expand Up @@ -654,7 +654,7 @@ async fn send_future_room_message() {
}

#[async_test]
async fn send_future_state() {
async fn send_future_state_event() {
let (_, mock_server, driver_handle) = run_test_driver(false).await;

negotiate_capabilities(
Expand Down

0 comments on commit 48c471b

Please sign in to comment.