use ruma_common::{
OwnedUserId,
api::{auth_scheme::NoAuthentication, request, response},
metadata,
serde::StringEnum,
};
use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
metadata! {
method: GET,
rate_limited: false,
authentication: NoAuthentication,
path: "/.well-known/matrix/support",
}
#[request(error = crate::Error)]
#[derive(Default)]
pub struct Request {}
#[response(error = crate::Error)]
pub struct Response {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub contacts: Vec<Contact>,
#[serde(skip_serializing_if = "Option::is_none")]
pub support_page: Option<String>,
}
impl Request {
pub fn new() -> Self {
Self {}
}
}
impl Response {
pub fn with_contacts(contacts: Vec<Contact>) -> Self {
Self { contacts, support_page: None }
}
pub fn with_support_page(support_page: String) -> Self {
Self { contacts: Vec::new(), support_page: Some(support_page) }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct Contact {
pub role: ContactRole,
#[serde(skip_serializing_if = "Option::is_none")]
pub email_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub matrix_id: Option<OwnedUserId>,
}
impl Contact {
pub fn with_email_address(role: ContactRole, email_address: String) -> Self {
Self { role, email_address: Some(email_address), matrix_id: None }
}
pub fn with_matrix_id(role: ContactRole, matrix_id: OwnedUserId) -> Self {
Self { role, email_address: None, matrix_id: Some(matrix_id) }
}
}
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, StringEnum)]
#[ruma_enum(rename_all(prefix = "m.role.", rule = "snake_case"))]
#[non_exhaustive]
pub enum ContactRole {
Admin,
Security,
#[cfg(feature = "unstable-msc4121")]
#[ruma_enum(rename = "support.feline.msc4121.role.moderator", alias = "m.role.moderator")]
Moderator,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}