Skip to main content

ruma_client_api/delayed_events/update_delayed_event/
unstable_v1.rs

1//! `msc4140` ([MSC])
2//!
3//! Old endpoint definition from MSC 4140. Does not correspond to the current state of the MSC.
4//!
5//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/blob/3ee73abe5f81252b00877cfb5db941ee9aa6c18d/proposals/4140-delayed-events-futures.md
6
7use ruma_common::{
8    api::{auth_scheme::AccessToken, request, response},
9    metadata,
10};
11
12use super::UpdateAction;
13
14metadata! {
15    method: POST,
16    rate_limited: true,
17    authentication: AccessToken,
18    history: {
19        unstable("org.matrix.msc4140") => "/_matrix/client/unstable/org.matrix.msc4140/delayed_events/{delay_id}",
20    }
21}
22
23/// Request type for the [`update_delayed_event`](crate::delayed_events::update_delayed_event)
24/// endpoint.
25#[request]
26pub struct Request {
27    /// The delay id that we want to update.
28    #[ruma_api(path)]
29    pub delay_id: String,
30    /// Which kind of update we want to request for the delayed event.
31    pub action: UpdateAction,
32}
33
34impl Request {
35    /// Creates a new `Request` to update a delayed event.
36    pub fn new(delay_id: String, action: UpdateAction) -> Self {
37        Self { delay_id, action }
38    }
39}
40
41/// Response type for the [`update_delayed_event`](crate::delayed_events::update_delayed_event)
42/// endpoint.
43#[response]
44pub struct Response {}
45impl Response {
46    /// Creates a new empty response for the
47    /// [`update_delayed_event`](crate::delayed_events::update_delayed_event) endpoint.
48    pub fn new() -> Self {
49        Self {}
50    }
51}
52
53#[cfg(all(test, feature = "client"))]
54mod tests {
55    use std::borrow::Cow;
56
57    use ruma_common::api::{
58        MatrixVersion, OutgoingRequest, SupportedVersions, auth_scheme::SendAccessToken,
59    };
60    use serde_json::{Value as JsonValue, json};
61
62    use super::{Request, UpdateAction};
63    #[test]
64    fn serialize_update_delayed_event_request() {
65        let supported = SupportedVersions {
66            versions: [MatrixVersion::V1_1].into(),
67            features: Default::default(),
68        };
69        let request: http::Request<Vec<u8>> = Request::new("1234".to_owned(), UpdateAction::Cancel)
70            .try_into_http_request(
71                "https://homeserver.tld",
72                SendAccessToken::IfRequired("auth_tok"),
73                Cow::Owned(supported),
74            )
75            .unwrap();
76
77        let (parts, body) = request.into_parts();
78
79        assert_eq!(
80            "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
81            parts.uri.to_string()
82        );
83        assert_eq!("POST", parts.method.to_string());
84        assert_eq!(
85            json!({"action": "cancel"}),
86            serde_json::from_str::<JsonValue>(std::str::from_utf8(&body).unwrap()).unwrap()
87        );
88    }
89}