ruma_federation_api/membership/prepare_knock_event/
unstable.rs

1//! `/unstable/xyz.amorgan.knock/` ([MSC])
2//!
3//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/2403
4
5use ruma_common::{
6    api::{path_builder::SinglePath, request, response, Metadata},
7    OwnedRoomId, OwnedUserId, RoomVersionId,
8};
9use serde_json::value::RawValue as RawJsonValue;
10
11/// Request type for the `create_knock_event_template` endpoint.
12#[request]
13pub struct Request {
14    /// The room ID that should receive the knock.
15    #[ruma_api(path)]
16    pub room_id: OwnedRoomId,
17
18    /// The user ID the knock event will be for.
19    #[ruma_api(path)]
20    pub user_id: OwnedUserId,
21
22    /// The room versions the sending has support for.
23    ///
24    /// Defaults to `vec![RoomVersionId::V1]`.
25    #[ruma_api(query)]
26    pub ver: Vec<RoomVersionId>,
27}
28
29impl Request {
30    /// Creates a `Request` with the given room ID and user ID.
31    pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self {
32        Self { room_id, user_id, ver: vec![RoomVersionId::V1] }
33    }
34}
35
36impl Metadata for Request {
37    const METHOD: http::Method = super::v1::Request::METHOD;
38    const RATE_LIMITED: bool = super::v1::Request::RATE_LIMITED;
39    type Authentication = <super::v1::Request as Metadata>::Authentication;
40    type PathBuilder = <super::v1::Request as Metadata>::PathBuilder;
41    const PATH_BUILDER: Self::PathBuilder = SinglePath::new(
42        "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/{room_id}/{user_id}",
43    );
44}
45
46impl From<super::v1::Request> for Request {
47    fn from(value: super::v1::Request) -> Self {
48        let super::v1::Request { room_id, user_id, ver } = value;
49        Self { room_id, user_id, ver }
50    }
51}
52
53impl From<Request> for super::v1::Request {
54    fn from(value: Request) -> Self {
55        let Request { room_id, user_id, ver } = value;
56        Self { room_id, user_id, ver }
57    }
58}
59
60/// Response type for the `create_knock_event_template` endpoint.
61#[response]
62pub struct Response {
63    /// The version of the room where the server is trying to knock.
64    pub room_version: RoomVersionId,
65
66    /// An unsigned template event.
67    ///
68    /// May differ between room versions.
69    pub event: Box<RawJsonValue>,
70}
71
72impl Response {
73    /// Creates a new `Response` with the given room version ID and event.
74    pub fn new(room_version: RoomVersionId, event: Box<RawJsonValue>) -> Self {
75        Self { room_version, event }
76    }
77}
78
79impl From<super::v1::Response> for Response {
80    fn from(value: super::v1::Response) -> Self {
81        let super::v1::Response { room_version, event } = value;
82        Self { room_version, event }
83    }
84}
85
86impl From<Response> for super::v1::Response {
87    fn from(value: Response) -> Self {
88        let Response { room_version, event } = value;
89        Self { room_version, event }
90    }
91}