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        OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
12        api::{request, response},
13        metadata,
14    };
15
16    use crate::authentication::ServerSignatures;
17
18    metadata! {
19        method: GET,
20        rate_limited: false,
21        authentication: ServerSignatures,
22        path: "/_matrix/federation/v1/query/directory",
23    }
24
25    /// Request type for the `get_room_information` endpoint.
26    #[request]
27    pub struct Request {
28        /// Room alias to query.
29        #[ruma_api(query)]
30        pub room_alias: OwnedRoomAliasId,
31    }
32
33    /// Response type for the `get_room_information` endpoint.
34    #[response]
35    pub struct Response {
36        /// Room ID mapped to queried alias.
37        pub room_id: OwnedRoomId,
38
39        /// An array of server names that are likely to hold the given room.
40        pub servers: Vec<OwnedServerName>,
41    }
42
43    impl Request {
44        /// Creates a new `Request` with the given room alias ID.
45        pub fn new(room_alias: OwnedRoomAliasId) -> Self {
46            Self { room_alias }
47        }
48    }
49
50    impl Response {
51        /// Creates a new `Response` with the given room IDs and servers.
52        pub fn new(room_id: OwnedRoomId, servers: Vec<OwnedServerName>) -> Self {
53            Self { room_id, servers }
54        }
55    }
56}