ruma_federation_api/knock/
create_knock_event_template.rs

1//! `GET /_matrix/federation/*/make_knock/{roomId}/{userId}`
2//!
3//! Send a request for a knock event template to a resident server.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1make_knockroomiduserid
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata, OwnedRoomId, OwnedUserId, RoomVersionId,
13    };
14    use serde_json::value::RawValue as RawJsonValue;
15
16    const METADATA: Metadata = metadata! {
17        method: GET,
18        rate_limited: false,
19        authentication: ServerSignatures,
20        history: {
21            unstable => "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/:room_id/:user_id",
22            1.1 => "/_matrix/federation/v1/make_knock/:room_id/:user_id",
23        }
24    };
25
26    /// Request type for the `create_knock_event_template` endpoint.
27    #[request]
28    pub struct Request {
29        /// The room ID that should receive the knock.
30        #[ruma_api(path)]
31        pub room_id: OwnedRoomId,
32
33        /// The user ID the knock event will be for.
34        #[ruma_api(path)]
35        pub user_id: OwnedUserId,
36
37        /// The room versions the sending has support for.
38        ///
39        /// Defaults to `vec![RoomVersionId::V1]`.
40        #[ruma_api(query)]
41        pub ver: Vec<RoomVersionId>,
42    }
43
44    /// Response type for the `create_knock_event_template` endpoint.
45    #[response]
46    pub struct Response {
47        /// The version of the room where the server is trying to knock.
48        pub room_version: RoomVersionId,
49
50        /// An unsigned template event.
51        ///
52        /// May differ between room versions.
53        pub event: Box<RawJsonValue>,
54    }
55
56    impl Request {
57        /// Creates a `Request` with the given room ID and user ID.
58        pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self {
59            Self { room_id, user_id, ver: vec![RoomVersionId::V1] }
60        }
61    }
62
63    impl Response {
64        /// Creates a new `Response` with the given room version ID and event.
65        pub fn new(room_version: RoomVersionId, event: Box<RawJsonValue>) -> Self {
66            Self { room_version, event }
67        }
68    }
69}