onechatsocial_models/v0/
servers.rs

1use super::{Channel, File};
2
3use onechatsocial_permissions::OverrideField;
4use std::collections::HashMap;
5
6#[cfg(feature = "validator")]
7use validator::Validate;
8
9auto_derived_partial!(
10    /// Server
11    pub struct Server {
12        /// Unique Id
13        #[cfg_attr(feature = "serde", serde(rename = "_id"))]
14        pub id: String,
15        /// User id of the owner
16        pub owner: String,
17
18        /// Name of the server
19        pub name: String,
20        /// Description for the server
21        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
22        pub description: Option<String>,
23
24        /// Channels within this server
25        // TODO: investigate if this is redundant and can be removed
26        pub channels: Vec<String>,
27        /// Categories for this server
28        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
29        pub categories: Option<Vec<Category>>,
30        /// Configuration for sending system event messages
31        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
32        pub system_messages: Option<SystemMessageChannels>,
33
34        /// Roles for this server
35        #[cfg_attr(
36            feature = "serde",
37            serde(
38                default = "HashMap::<String, Role>::new",
39                skip_serializing_if = "HashMap::<String, Role>::is_empty"
40            )
41        )]
42        pub roles: HashMap<String, Role>,
43        /// Default set of server and channel permissions
44        pub default_permissions: i64,
45
46        /// Icon attachment
47        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
48        pub icon: Option<File>,
49        /// Banner attachment
50        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
51        pub banner: Option<File>,
52
53        /// Bitfield of server flags
54        #[cfg_attr(
55            feature = "serde",
56            serde(skip_serializing_if = "crate::if_zero_u32", default)
57        )]
58        pub flags: u32,
59
60        /// Whether this server is flagged as not safe for work
61        #[cfg_attr(
62            feature = "serde",
63            serde(skip_serializing_if = "crate::if_false", default)
64        )]
65        pub nsfw: bool,
66        /// Whether to enable analytics
67        #[cfg_attr(
68            feature = "serde",
69            serde(skip_serializing_if = "crate::if_false", default)
70        )]
71        pub analytics: bool,
72        /// Whether this server should be publicly discoverable
73        #[cfg_attr(
74            feature = "serde",
75            serde(skip_serializing_if = "crate::if_false", default)
76        )]
77        pub discoverable: bool,
78    },
79    "PartialServer"
80);
81
82auto_derived_partial!(
83    /// Role
84    pub struct Role {
85        /// Role name
86        pub name: String,
87        /// Permissions available to this role
88        pub permissions: OverrideField,
89        /// Colour used for this role
90        ///
91        /// This can be any valid CSS colour
92        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
93        pub colour: Option<String>,
94        /// Whether this role should be shown separately on the member sidebar
95        #[cfg_attr(
96            feature = "serde",
97            serde(skip_serializing_if = "crate::if_false", default)
98        )]
99        pub hoist: bool,
100        /// Ranking of this role
101        #[cfg_attr(feature = "serde", serde(default))]
102        pub rank: i64,
103    },
104    "PartialRole"
105);
106
107auto_derived!(
108    /// Optional fields on server object
109    pub enum FieldsServer {
110        Description,
111        Categories,
112        SystemMessages,
113        Icon,
114        Banner,
115    }
116
117    /// Optional fields on server object
118    pub enum FieldsRole {
119        Colour,
120    }
121
122    /// Channel category
123    pub struct Category {
124        /// Unique ID for this category
125        pub id: String,
126        /// Title for this category
127        pub title: String,
128        /// Channels in this category
129        pub channels: Vec<String>,
130    }
131
132    /// System message channel assignments
133    pub struct SystemMessageChannels {
134        /// ID of channel to send user join messages in
135        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
136        pub user_joined: Option<String>,
137        /// ID of channel to send user left messages in
138        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
139        pub user_left: Option<String>,
140        /// ID of channel to send user kicked messages in
141        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
142        pub user_kicked: Option<String>,
143        /// ID of channel to send user banned messages in
144        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
145        pub user_banned: Option<String>,
146    }
147
148    /// Information about new server to create
149    #[derive(Default)]
150    #[cfg_attr(feature = "validator", derive(Validate))]
151    pub struct DataCreateServer {
152        /// Server name
153        #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
154        pub name: String,
155        /// Server description
156        #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
157        pub description: Option<String>,
158        /// Whether this server is age-restricted
159        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
160        pub nsfw: Option<bool>,
161    }
162
163    /// Information returned when creating server
164    pub struct CreateServerLegacyResponse {
165        /// Server object
166        pub server: Server,
167        /// Default channels
168        pub channels: Vec<Channel>,
169    }
170);