ruma_federation_api/event/
get_event.rs

1//! `GET /_matrix/federation/*/event/{eventId}`
2//!
3//! Retrieves a single event.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1eventeventid
9
10    use ruma_common::{
11        MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName,
12        api::{request, response},
13        metadata,
14    };
15    use serde_json::value::RawValue as RawJsonValue;
16
17    use crate::authentication::ServerSignatures;
18
19    metadata! {
20        method: GET,
21        rate_limited: false,
22        authentication: ServerSignatures,
23        path: "/_matrix/federation/v1/event/{event_id}",
24    }
25
26    /// Request type for the `get_event` endpoint.
27    #[request]
28    pub struct Request {
29        /// The event ID to get.
30        #[ruma_api(path)]
31        pub event_id: OwnedEventId,
32    }
33
34    /// Response type for the `get_event` endpoint.
35    #[response]
36    pub struct Response {
37        /// The `server_name` of the homeserver sending this transaction.
38        pub origin: OwnedServerName,
39
40        /// Time on originating homeserver when this transaction started.
41        pub origin_server_ts: MilliSecondsSinceUnixEpoch,
42
43        /// The event.
44        #[serde(rename = "pdus", with = "ruma_common::serde::single_element_seq")]
45        pub pdu: Box<RawJsonValue>,
46    }
47
48    impl Request {
49        /// Creates a new `Request` with the given event id.
50        pub fn new(event_id: OwnedEventId) -> Self {
51            Self { event_id }
52        }
53    }
54
55    impl Response {
56        /// Creates a new `Response` with the given server name, timestamp, and event.
57        pub fn new(
58            origin: OwnedServerName,
59            origin_server_ts: MilliSecondsSinceUnixEpoch,
60            pdu: Box<RawJsonValue>,
61        ) -> Self {
62            Self { origin, origin_server_ts, pdu }
63        }
64    }
65}