ruma_federation_api/event/get_event_by_timestamp/
unstable.rs

1//! `/unstable/org.matrix.msc3030/` ([MSC])
2//!
3//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3030
4
5use ruma_common::{
6    api::{path_builder::SinglePath, request, response, Direction, Metadata},
7    MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
8};
9
10/// Request type for the `get_event_by_timestamp` endpoint.
11#[request]
12pub struct Request {
13    /// The ID of the room the event is in.
14    #[ruma_api(path)]
15    pub room_id: OwnedRoomId,
16
17    /// The timestamp to search from.
18    #[ruma_api(query)]
19    pub ts: MilliSecondsSinceUnixEpoch,
20
21    /// The direction in which to search.
22    #[ruma_api(query)]
23    pub dir: Direction,
24}
25
26impl Request {
27    /// Creates a new `Request` with the given room ID, timestamp and direction.
28    pub fn new(room_id: OwnedRoomId, ts: MilliSecondsSinceUnixEpoch, dir: Direction) -> Self {
29        Self { room_id, ts, dir }
30    }
31}
32
33impl Metadata for Request {
34    const METHOD: http::Method = super::v1::Request::METHOD;
35    const RATE_LIMITED: bool = super::v1::Request::RATE_LIMITED;
36    type Authentication = <super::v1::Request as Metadata>::Authentication;
37    type PathBuilder = <super::v1::Request as Metadata>::PathBuilder;
38    const PATH_BUILDER: Self::PathBuilder = SinglePath::new(
39        "/_matrix/federation/unstable/org.matrix.msc3030/timestamp_to_event/{room_id}",
40    );
41}
42
43impl From<super::v1::Request> for Request {
44    fn from(value: super::v1::Request) -> Self {
45        let super::v1::Request { room_id, ts, dir } = value;
46        Self { room_id, ts, dir }
47    }
48}
49
50impl From<Request> for super::v1::Request {
51    fn from(value: Request) -> Self {
52        let Request { room_id, ts, dir } = value;
53        Self { room_id, ts, dir }
54    }
55}
56
57/// Response type for the `get_event_by_timestamp` endpoint.
58#[response]
59pub struct Response {
60    /// The ID of the event found.
61    pub event_id: OwnedEventId,
62
63    /// The event's timestamp.
64    pub origin_server_ts: MilliSecondsSinceUnixEpoch,
65}
66
67impl Response {
68    /// Creates a new `Response` with the given event ID and timestamp.
69    pub fn new(event_id: OwnedEventId, origin_server_ts: MilliSecondsSinceUnixEpoch) -> Self {
70        Self { event_id, origin_server_ts }
71    }
72}
73
74impl From<super::v1::Response> for Response {
75    fn from(value: super::v1::Response) -> Self {
76        let super::v1::Response { event_id, origin_server_ts } = value;
77        Self { event_id, origin_server_ts }
78    }
79}
80
81impl From<Response> for super::v1::Response {
82    fn from(value: Response) -> Self {
83        let Response { event_id, origin_server_ts } = value;
84        Self { event_id, origin_server_ts }
85    }
86}