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.
67use ruma_common::{
8 api::{request, response, Metadata},
9 metadata,
10 serde::StringEnum,
11 OwnedUserId,
12};
13use serde::{Deserialize, Serialize};
1415use crate::PrivOwnedStr;
1617const METADATA: Metadata = metadata! {
18 method: GET,
19 rate_limited: false,
20 authentication: None,
21 history: {
221.10 => "/.well-known/matrix/support",
23 }
24};
2526/// Request type for the `discover_support` endpoint.
27#[request(error = crate::Error)]
28#[derive(Default)]
29pub struct Request {}
3031/// 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")]
39pub contacts: Vec<Contact>,
4041/// 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")]
46pub support_page: Option<String>,
47}
4849impl Request {
50/// Creates an empty `Request`.
51pub fn new() -> Self {
52Self {}
53 }
54}
5556impl Response {
57/// Creates a new `Response` with the given contacts.
58pub fn with_contacts(contacts: Vec<Contact>) -> Self {
59Self { contacts, support_page: None }
60 }
6162/// Creates a new `Response` with the given support page.
63pub fn with_support_page(support_page: String) -> Self {
64Self { contacts: Vec::new(), support_page: Some(support_page) }
65 }
66}
6768/// 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.
73pub role: ContactRole,
7475/// 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")]
79pub email_address: Option<String>,
8081/// 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")]
88pub matrix_id: Option<OwnedUserId>,
89}
9091impl Contact {
92/// Creates a new `Contact` with the given role and email address.
93pub fn with_email_address(role: ContactRole, email_address: String) -> Self {
94Self { role, email_address: Some(email_address), matrix_id: None }
95 }
9697/// Creates a new `Contact` with the given role and Matrix User ID.
98pub fn with_matrix_id(role: ContactRole, matrix_id: OwnedUserId) -> Self {
99Self { role, email_address: None, matrix_id: Some(matrix_id) }
100 }
101}
102103/// 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.
110Admin,
111112/// A role intended for sensitive requests.
113Security,
114115/// 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")]
120Moderator,
121122#[doc(hidden)]
123_Custom(PrivOwnedStr),
124}