Skip to main content

ruma_client_api/delayed_events/update_delayed_event/
msc4140_v1.rs

1//! `/unstable/org.matrix.msc4140/` ([MSC])
2//!
3//! Old endpoint definition from MSC4140. 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` endpoint.
24#[request]
25pub struct Request {
26    /// The delay id that we want to update.
27    #[ruma_api(path)]
28    pub delay_id: String,
29
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` endpoint.
42#[response]
43pub struct Response {}
44impl Response {
45    /// Creates a new empty response.
46    pub fn new() -> Self {
47        Self {}
48    }
49}
50
51#[cfg(all(test, feature = "client"))]
52mod tests {
53    use std::borrow::Cow;
54
55    use ruma_common::api::{
56        MatrixVersion, OutgoingRequestExt as _, SupportedVersions, auth_scheme::SendAccessToken,
57    };
58    use serde_json::{Value as JsonValue, json};
59
60    use super::{Request, UpdateAction};
61    #[test]
62    fn serialize_update_delayed_event_request() {
63        let supported = SupportedVersions {
64            versions: [MatrixVersion::V1_1].into(),
65            features: Default::default(),
66        };
67        let request: http::Request<Vec<u8>> = Request::new("1234".to_owned(), UpdateAction::Cancel)
68            .try_into_http_request(
69                "https://homeserver.tld",
70                SendAccessToken::IfRequired("auth_tok"),
71                Cow::Owned(supported),
72            )
73            .unwrap();
74
75        let (parts, body) = request.into_parts();
76
77        assert_eq!(
78            "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
79            parts.uri
80        );
81        assert_eq!("POST", parts.method);
82        assert_eq!(
83            json!({"action": "cancel"}),
84            serde_json::from_slice::<JsonValue>(&body).unwrap()
85        );
86    }
87}