ruma_client_api/discovery/
discover_support.rs

1//! `GET /.well-known/matrix/support` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixsupport
4//!
5//! Get server admin contact and support page of a homeserver's domain.
6
7use ruma_common::{
8    api::{auth_scheme::NoAuthentication, request, response},
9    metadata,
10    serde::StringEnum,
11    OwnedUserId,
12};
13use serde::{Deserialize, Serialize};
14
15use crate::PrivOwnedStr;
16
17metadata! {
18    method: GET,
19    rate_limited: false,
20    authentication: NoAuthentication,
21    path: "/.well-known/matrix/support",
22}
23
24/// Request type for the `discover_support` endpoint.
25#[request(error = crate::Error)]
26#[derive(Default)]
27pub struct Request {}
28
29/// Response type for the `discover_support` endpoint.
30#[response(error = crate::Error)]
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
89impl Contact {
90    /// Creates a new `Contact` with the given role and email address.
91    pub fn with_email_address(role: ContactRole, email_address: String) -> Self {
92        Self { role, email_address: Some(email_address), matrix_id: None }
93    }
94
95    /// Creates a new `Contact` with the given role and Matrix User ID.
96    pub fn with_matrix_id(role: ContactRole, matrix_id: OwnedUserId) -> Self {
97        Self { role, email_address: None, matrix_id: Some(matrix_id) }
98    }
99}
100
101/// An informal description of what the contact methods are used for.
102#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
103#[derive(Clone, StringEnum)]
104#[ruma_enum(rename_all = "m.role.snake_case")]
105#[non_exhaustive]
106pub enum ContactRole {
107    /// A catch-all role for any queries.
108    Admin,
109
110    /// A role intended for sensitive requests.
111    Security,
112
113    /// A role for moderation-related queries according to [MSC4121](https://github.com/matrix-org/matrix-spec-proposals/pull/4121).
114    ///
115    /// The future prefix for this if accepted will be `m.role.moderator`
116    #[cfg(feature = "unstable-msc4121")]
117    #[ruma_enum(rename = "support.feline.msc4121.role.moderator", alias = "m.role.moderator")]
118    Moderator,
119
120    #[doc(hidden)]
121    _Custom(PrivOwnedStr),
122}