ruma_client_api/dehydrated_device/
get_events.rs

1//! `POST /_matrix/client/*/dehydrated_device/{device_id}/events`
2//!
3//! Get to-device events for a dehydrated device.
4
5pub mod unstable {
6    //! `msc3814` ([MSC])
7    //!
8    //! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3814
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata,
13        serde::Raw,
14        OwnedDeviceId,
15    };
16    use ruma_events::AnyToDeviceEvent;
17
18    const METADATA: Metadata = metadata! {
19        method: POST,
20        rate_limited: false,
21        authentication: AccessToken,
22        history: {
23            unstable => "/_matrix/client/unstable/org.matrix.msc3814.v1/dehydrated_device/:device_id/events",
24        }
25    };
26
27    /// Request type for the `dehydrated_device/{device_id}/events` endpoint.
28    #[request(error = crate::Error)]
29    pub struct Request {
30        /// The unique ID of the device for which we would like to fetch events.
31        #[ruma_api(path)]
32        pub device_id: OwnedDeviceId,
33        /// A point in time to continue getting events from.
34        ///
35        /// Should be a token from the `next_batch` field of a previous `/events`
36        /// request.
37        #[serde(skip_serializing_if = "Option::is_none")]
38        pub next_batch: Option<String>,
39    }
40
41    /// Request type for the `dehydrated_device/{device_id}/events` endpoint.
42    #[response(error = crate::Error)]
43    pub struct Response {
44        /// The batch token to supply in the `since` param of the next `/events` request. Will be
45        /// none if no further events can be found.
46        pub next_batch: Option<String>,
47
48        /// Messages sent directly between devices.
49        pub events: Vec<Raw<AnyToDeviceEvent>>,
50    }
51
52    impl Request {
53        /// Create a new request.
54        pub fn new(device_id: OwnedDeviceId) -> Self {
55            Self { device_id, next_batch: None }
56        }
57    }
58
59    impl Response {
60        /// Create a new response with the given events.
61        pub fn new(events: Vec<Raw<AnyToDeviceEvent>>) -> Self {
62            Self { next_batch: None, events }
63        }
64    }
65}