ruma_client_api/discovery/
discover_homeserver.rs1use ruma_common::{
8 api::{request, response, Metadata},
9 metadata,
10};
11use serde::{Deserialize, Serialize};
12
13const METADATA: Metadata = metadata! {
14 method: GET,
15 rate_limited: false,
16 authentication: None,
17 history: {
18 1.0 => "/.well-known/matrix/client",
19 }
20};
21
22#[request(error = crate::Error)]
24#[derive(Default)]
25pub struct Request {}
26
27#[response(error = crate::Error)]
29pub struct Response {
30 #[serde(rename = "m.homeserver")]
32 pub homeserver: HomeserverInfo,
33
34 #[serde(rename = "m.identity_server", skip_serializing_if = "Option::is_none")]
36 pub identity_server: Option<IdentityServerInfo>,
37
38 #[cfg(feature = "unstable-msc3488")]
40 #[serde(
41 rename = "org.matrix.msc3488.tile_server",
42 alias = "m.tile_server",
43 skip_serializing_if = "Option::is_none"
44 )]
45 pub tile_server: Option<TileServerInfo>,
46
47 #[cfg(feature = "unstable-msc2965")]
49 #[serde(
50 rename = "org.matrix.msc2965.authentication",
51 alias = "m.authentication",
52 skip_serializing_if = "Option::is_none"
53 )]
54 pub authentication: Option<AuthenticationServerInfo>,
55
56 #[cfg(feature = "unstable-msc3575")]
58 #[serde(rename = "org.matrix.msc3575.proxy", skip_serializing_if = "Option::is_none")]
59 pub sliding_sync_proxy: Option<SlidingSyncProxyInfo>,
60}
61
62impl Request {
63 pub fn new() -> Self {
65 Self {}
66 }
67}
68
69impl Response {
70 pub fn new(homeserver: HomeserverInfo) -> Self {
72 Self {
73 homeserver,
74 identity_server: None,
75 #[cfg(feature = "unstable-msc3488")]
76 tile_server: None,
77 #[cfg(feature = "unstable-msc2965")]
78 authentication: None,
79 #[cfg(feature = "unstable-msc3575")]
80 sliding_sync_proxy: None,
81 }
82 }
83}
84
85#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
87#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
88pub struct HomeserverInfo {
89 pub base_url: String,
91}
92
93impl HomeserverInfo {
94 pub fn new(base_url: String) -> Self {
96 Self { base_url }
97 }
98}
99
100#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
102#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
103pub struct IdentityServerInfo {
104 pub base_url: String,
106}
107
108impl IdentityServerInfo {
109 pub fn new(base_url: String) -> Self {
111 Self { base_url }
112 }
113}
114
115#[cfg(feature = "unstable-msc3488")]
117#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
118#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
119pub struct TileServerInfo {
120 pub map_style_url: String,
124}
125
126#[cfg(feature = "unstable-msc3488")]
127impl TileServerInfo {
128 pub fn new(map_style_url: String) -> Self {
130 Self { map_style_url }
131 }
132}
133
134#[cfg(feature = "unstable-msc2965")]
136#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
137#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
138pub struct AuthenticationServerInfo {
139 pub issuer: String,
141
142 #[serde(skip_serializing_if = "Option::is_none")]
145 pub account: Option<String>,
146}
147
148#[cfg(feature = "unstable-msc2965")]
149impl AuthenticationServerInfo {
150 pub fn new(issuer: String, account: Option<String>) -> Self {
152 Self { issuer, account }
153 }
154}
155
156#[cfg(feature = "unstable-msc3575")]
158#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
159#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
160pub struct SlidingSyncProxyInfo {
161 pub url: String,
163}
164
165#[cfg(feature = "unstable-msc3575")]
166impl SlidingSyncProxyInfo {
167 pub fn new(url: String) -> Self {
169 Self { url }
170 }
171}