ruma_client_api/discovery/discover_support.rs
1//! `GET /.well-known/matrix/support` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/v1.18/client-server-api/#getwell-knownmatrixsupport
4//!
5//! Get server admin contact and support page of a homeserver's domain.
6
7use ruma_common::{
8 OwnedUserId,
9 api::{auth_scheme::NoAccessToken, request, response},
10 metadata,
11 serde::StringEnum,
12};
13use serde::{Deserialize, Serialize};
14
15use crate::PrivOwnedStr;
16
17metadata! {
18 method: GET,
19 rate_limited: false,
20 authentication: NoAccessToken,
21 path: "/.well-known/matrix/support",
22}
23
24/// Request type for the `discover_support` endpoint.
25#[request]
26#[derive(Default)]
27pub struct Request {}
28
29/// Response type for the `discover_support` endpoint.
30#[response]
31pub struct Response {
32 /// Ways to contact the server administrator.
33 ///
34 /// At least one of `contacts` or `support_page` is required. If only `contacts` is set, it
35 /// must contain at least one item.
36 #[serde(default, skip_serializing_if = "Vec::is_empty")]
37 pub contacts: Vec<Contact>,
38
39 /// The URL of a page to give users help specific to the homeserver, like extra
40 /// login/registration steps.
41 ///
42 /// At least one of `contacts` or `support_page` is required.
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub support_page: Option<String>,
45}
46
47impl Request {
48 /// Creates an empty `Request`.
49 pub fn new() -> Self {
50 Self {}
51 }
52}
53
54impl Response {
55 /// Creates a new `Response` with the given contacts.
56 pub fn with_contacts(contacts: Vec<Contact>) -> Self {
57 Self { contacts, support_page: None }
58 }
59
60 /// Creates a new `Response` with the given support page.
61 pub fn with_support_page(support_page: String) -> Self {
62 Self { contacts: Vec::new(), support_page: Some(support_page) }
63 }
64}
65
66/// A way to contact the server administrator.
67#[derive(Clone, Debug, Deserialize, Serialize)]
68#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
69pub struct Contact {
70 /// An informal description of what the contact methods are used for.
71 pub role: ContactRole,
72
73 /// An email address to reach the administrator.
74 ///
75 /// At least one of `matrix_id` or `email_address` is required.
76 #[serde(skip_serializing_if = "Option::is_none")]
77 pub email_address: Option<String>,
78
79 /// A Matrix User ID representing the administrator.
80 ///
81 /// It could be an account registered on a different homeserver so the administrator can be
82 /// contacted when the homeserver is down.
83 ///
84 /// At least one of `matrix_id` or `email_address` is required.
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub matrix_id: Option<OwnedUserId>,
87
88 /// An optional URI leading to a PGP key that may be used to encrypt messages sent to the
89 /// contact.
90 ///
91 /// This field uses the unstable prefix defined in [MSC4439].
92 ///
93 /// [MSC4439]: https://github.com/matrix-org/matrix-spec-proposals/pull/4439
94 #[cfg(feature = "unstable-msc4439")]
95 #[serde(skip_serializing_if = "Option::is_none")]
96 #[serde(rename = "dev.zirco.msc4439.pgp_key")]
97 pub pgp_key: Option<String>,
98}
99
100impl Contact {
101 /// Creates a new `Contact` with the given role and email address.
102 pub fn with_email_address(role: ContactRole, email_address: String) -> Self {
103 Self {
104 role,
105 email_address: Some(email_address),
106 matrix_id: None,
107 #[cfg(feature = "unstable-msc4439")]
108 pgp_key: None,
109 }
110 }
111
112 /// Creates a new `Contact` with the given role and Matrix User ID.
113 pub fn with_matrix_id(role: ContactRole, matrix_id: OwnedUserId) -> Self {
114 Self {
115 role,
116 email_address: None,
117 matrix_id: Some(matrix_id),
118 #[cfg(feature = "unstable-msc4439")]
119 pgp_key: None,
120 }
121 }
122}
123
124/// An informal description of what the contact methods are used for.
125#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
126#[derive(Clone, StringEnum)]
127#[ruma_enum(rename_all(prefix = "m.role.", rule = "snake_case"))]
128#[non_exhaustive]
129pub enum ContactRole {
130 /// A catch-all role for any queries.
131 Admin,
132
133 /// A role intended for sensitive requests.
134 Security,
135
136 /// A role for moderation-related queries according to [MSC4121](https://github.com/matrix-org/matrix-spec-proposals/pull/4121).
137 ///
138 /// The future prefix for this if accepted will be `m.role.moderator`
139 #[cfg(feature = "unstable-msc4121")]
140 #[ruma_enum(rename = "support.feline.msc4121.role.moderator", alias = "m.role.moderator")]
141 Moderator,
142
143 #[doc(hidden)]
144 _Custom(PrivOwnedStr),
145}