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::{request, response, Metadata},
9    metadata,
10    serde::StringEnum,
11    OwnedUserId,
12};
13use serde::{Deserialize, Serialize};
14
15use crate::PrivOwnedStr;
16
17const METADATA: Metadata = metadata! {
18    method: GET,
19    rate_limited: false,
20    authentication: None,
21    history: {
22        1.10 => "/.well-known/matrix/support",
23    }
24};
25
26/// Request type for the `discover_support` endpoint.
27#[request(error = crate::Error)]
28#[derive(Default)]
29pub struct Request {}
30
31/// Response type for the `discover_support` endpoint.
32#[response(error = crate::Error)]
33pub struct Response {
34    /// Ways to contact the server administrator.
35    ///
36    /// At least one of `contacts` or `support_page` is required. If only `contacts` is set, it
37    /// must contain at least one item.
38    #[serde(default, skip_serializing_if = "Vec::is_empty")]
39    pub contacts: Vec<Contact>,
40
41    /// The URL of a page to give users help specific to the homeserver, like extra
42    /// login/registration steps.
43    ///
44    /// At least one of `contacts` or `support_page` is required.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub support_page: Option<String>,
47}
48
49impl Request {
50    /// Creates an empty `Request`.
51    pub fn new() -> Self {
52        Self {}
53    }
54}
55
56impl Response {
57    /// Creates a new `Response` with the given contacts.
58    pub fn with_contacts(contacts: Vec<Contact>) -> Self {
59        Self { contacts, support_page: None }
60    }
61
62    /// Creates a new `Response` with the given support page.
63    pub fn with_support_page(support_page: String) -> Self {
64        Self { contacts: Vec::new(), support_page: Some(support_page) }
65    }
66}
67
68/// A way to contact the server administrator.
69#[derive(Clone, Debug, Deserialize, Serialize)]
70#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
71pub struct Contact {
72    /// An informal description of what the contact methods are used for.
73    pub role: ContactRole,
74
75    /// An email address to reach the administrator.
76    ///
77    /// At least one of `matrix_id` or `email_address` is required.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub email_address: Option<String>,
80
81    /// A Matrix User ID representing the administrator.
82    ///
83    /// It could be an account registered on a different homeserver so the administrator can be
84    /// contacted when the homeserver is down.
85    ///
86    /// At least one of `matrix_id` or `email_address` is required.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub matrix_id: Option<OwnedUserId>,
89}
90
91impl Contact {
92    /// Creates a new `Contact` with the given role and email address.
93    pub fn with_email_address(role: ContactRole, email_address: String) -> Self {
94        Self { role, email_address: Some(email_address), matrix_id: None }
95    }
96
97    /// Creates a new `Contact` with the given role and Matrix User ID.
98    pub fn with_matrix_id(role: ContactRole, matrix_id: OwnedUserId) -> Self {
99        Self { role, email_address: None, matrix_id: Some(matrix_id) }
100    }
101}
102
103/// An informal description of what the contact methods are used for.
104#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
105#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
106#[ruma_enum(rename_all = "m.role.snake_case")]
107#[non_exhaustive]
108pub enum ContactRole {
109    /// A catch-all role for any queries.
110    Admin,
111
112    /// A role intended for sensitive requests.
113    Security,
114
115    /// A role for moderation-related queries according to [MSC4121](https://github.com/matrix-org/matrix-spec-proposals/pull/4121).
116    ///
117    /// The future prefix for this if accepted will be `m.role.moderator`
118    #[cfg(feature = "unstable-msc4121")]
119    #[ruma_enum(rename = "support.feline.msc4121.role.moderator", alias = "m.role.moderator")]
120    Moderator,
121
122    #[doc(hidden)]
123    _Custom(PrivOwnedStr),
124}