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