ruma_federation_api/query/
get_room_information.rs

1//! `GET /_matrix/federation/*/query/directory`
2//!
3//! Get mapped room ID and resident homeservers for a given room alias.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1querydirectory
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata, OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
13    };
14
15    const METADATA: Metadata = metadata! {
16        method: GET,
17        rate_limited: false,
18        authentication: ServerSignatures,
19        history: {
20            1.0 => "/_matrix/federation/v1/query/directory",
21        }
22    };
23
24    /// Request type for the `get_room_information` endpoint.
25    #[request]
26    pub struct Request {
27        /// Room alias to query.
28        #[ruma_api(query)]
29        pub room_alias: OwnedRoomAliasId,
30    }
31
32    /// Response type for the `get_room_information` endpoint.
33    #[response]
34    pub struct Response {
35        /// Room ID mapped to queried alias.
36        pub room_id: OwnedRoomId,
37
38        /// An array of server names that are likely to hold the given room.
39        pub servers: Vec<OwnedServerName>,
40    }
41
42    impl Request {
43        /// Creates a new `Request` with the given room alias ID.
44        pub fn new(room_alias: OwnedRoomAliasId) -> Self {
45            Self { room_alias }
46        }
47    }
48
49    impl Response {
50        /// Creates a new `Response` with the given room IDs and servers.
51        pub fn new(room_id: OwnedRoomId, servers: Vec<OwnedServerName>) -> Self {
52            Self { room_id, servers }
53        }
54    }
55}