ruma_client_api/alias/
get_alias.rs

1//! `GET /_matrix/client/*/directory/room/{roomAlias}`
2//!
3//! Resolve a room alias to a room ID.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3directoryroomroomalias
9
10    use ruma_common::{
11        OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
12        api::{auth_scheme::NoAuthentication, request, response},
13        metadata,
14    };
15
16    metadata! {
17        method: GET,
18        rate_limited: false,
19        authentication: NoAuthentication,
20        history: {
21            1.0 => "/_matrix/client/r0/directory/room/{room_alias}",
22            1.1 => "/_matrix/client/v3/directory/room/{room_alias}",
23        }
24    }
25
26    /// Request type for the `get_alias` endpoint.
27    #[request(error = crate::Error)]
28    pub struct Request {
29        /// The room alias.
30        #[ruma_api(path)]
31        pub room_alias: OwnedRoomAliasId,
32    }
33
34    /// Response type for the `get_alias` endpoint.
35    #[response(error = crate::Error)]
36    pub struct Response {
37        /// The room ID for this room alias.
38        pub room_id: OwnedRoomId,
39
40        /// A list of servers that are aware of this room ID.
41        pub servers: Vec<OwnedServerName>,
42    }
43
44    impl Request {
45        /// Creates a new `Request` with the given room alias id.
46        pub fn new(room_alias: OwnedRoomAliasId) -> Self {
47            Self { room_alias }
48        }
49    }
50
51    impl Response {
52        /// Creates a new `Response` with the given room id and servers
53        pub fn new(room_id: OwnedRoomId, servers: Vec<OwnedServerName>) -> Self {
54            Self { room_id, servers }
55        }
56    }
57}