ruma_federation_api/event/get_event_by_timestamp/
v1.rs

1//! `/v1/` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1timestamp_to_eventroomid
4
5use ruma_common::{
6    api::{request, response, Direction},
7    metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
8};
9
10use crate::authentication::ServerSignatures;
11
12metadata! {
13    method: GET,
14    rate_limited: false,
15    authentication: ServerSignatures,
16    path: "/_matrix/federation/v1/timestamp_to_event/{room_id}",
17}
18
19/// Request type for the `get_event_by_timestamp` endpoint.
20#[request]
21pub struct Request {
22    /// The ID of the room the event is in.
23    #[ruma_api(path)]
24    pub room_id: OwnedRoomId,
25
26    /// The timestamp to search from.
27    #[ruma_api(query)]
28    pub ts: MilliSecondsSinceUnixEpoch,
29
30    /// The direction in which to search.
31    #[ruma_api(query)]
32    pub dir: Direction,
33}
34
35/// Response type for the `get_event_by_timestamp` endpoint.
36#[response]
37pub struct Response {
38    /// The ID of the event found.
39    pub event_id: OwnedEventId,
40
41    /// The event's timestamp.
42    pub origin_server_ts: MilliSecondsSinceUnixEpoch,
43}
44
45impl Request {
46    /// Creates a new `Request` with the given room ID, timestamp and direction.
47    pub fn new(room_id: OwnedRoomId, ts: MilliSecondsSinceUnixEpoch, dir: Direction) -> Self {
48        Self { room_id, ts, dir }
49    }
50}
51
52impl Response {
53    /// Creates a new `Response` with the given event ID and timestamp.
54    pub fn new(event_id: OwnedEventId, origin_server_ts: MilliSecondsSinceUnixEpoch) -> Self {
55        Self { event_id, origin_server_ts }
56    }
57}