ruma_events/room/message/
server_notice.rs

1use ruma_common::serde::StringEnum;
2use serde::{Deserialize, Serialize};
3
4use crate::PrivOwnedStr;
5
6/// The payload for a server notice message.
7#[derive(Clone, Debug, Deserialize, Serialize)]
8#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
9#[serde(tag = "msgtype", rename = "m.server_notice")]
10pub struct ServerNoticeMessageEventContent {
11    /// A human-readable description of the notice.
12    pub body: String,
13
14    /// The type of notice being represented.
15    pub server_notice_type: ServerNoticeType,
16
17    /// A URI giving a contact method for the server administrator.
18    ///
19    /// Required if the notice type is `m.server_notice.usage_limit_reached`.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub admin_contact: Option<String>,
22
23    /// The kind of usage limit the server has exceeded.
24    ///
25    /// Required if the notice type is `m.server_notice.usage_limit_reached`.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub limit_type: Option<LimitType>,
28}
29
30impl ServerNoticeMessageEventContent {
31    /// Creates a new `ServerNoticeMessageEventContent` with the given body and notice type.
32    pub fn new(body: String, server_notice_type: ServerNoticeType) -> Self {
33        Self { body, server_notice_type, admin_contact: None, limit_type: None }
34    }
35}
36
37/// Types of server notices.
38#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
39#[derive(Clone, PartialEq, Eq, StringEnum)]
40#[non_exhaustive]
41pub enum ServerNoticeType {
42    /// The server has exceeded some limit which requires the server administrator to intervene.
43    #[ruma_enum(rename = "m.server_notice.usage_limit_reached")]
44    UsageLimitReached,
45
46    #[doc(hidden)]
47    _Custom(PrivOwnedStr),
48}
49
50/// Types of usage limits.
51#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
52#[derive(Clone, PartialEq, Eq, StringEnum)]
53#[ruma_enum(rename_all = "snake_case")]
54#[non_exhaustive]
55pub enum LimitType {
56    /// The server's number of active users in the last 30 days has exceeded the maximum.
57    ///
58    /// New connections are being refused by the server. What defines "active" is left as an
59    /// implementation detail, however servers are encouraged to treat syncing users as "active".
60    MonthlyActiveUser,
61
62    #[doc(hidden)]
63    _Custom(PrivOwnedStr),
64}