ruma_federation_api/membership/prepare_knock_event/
v1.rs

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