rive_models/
server.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    attachment::Attachment,
7    member::MemberCompositeKey,
8    permission::{OverrideField, Permission},
9};
10
11/// Representation of a server role
12#[derive(Deserialize, Debug, Clone)]
13pub struct Role {
14    /// Role name
15    pub name: String,
16    /// Permissions available to this role
17    pub permissions: OverrideField,
18    /// Colour used for this role
19    ///
20    /// This can be any valid CSS colour
21    pub colour: Option<String>,
22    /// Whether this role should be shown separately on the member sidebar
23    #[serde(default)]
24    pub hoist: bool,
25    /// Ranking of this role
26    #[serde(default)]
27    pub rank: i64,
28}
29
30/// New role response
31#[derive(Deserialize, Debug, Clone)]
32pub struct NewRole {
33    /// ID of the role
34    pub id: String,
35    /// New role
36    pub role: Role,
37}
38
39/// Partial representation of a server role
40#[derive(Deserialize, Debug, Clone)]
41pub struct PartialRole {
42    /// Role name
43    pub name: Option<String>,
44    /// Permissions available to this role
45    pub permissions: Option<OverrideField>,
46    /// Colour used for this role
47    ///
48    /// This can be any valid CSS colour
49    pub colour: Option<String>,
50    /// Whether this role should be shown separately on the member sidebar
51    pub hoist: Option<bool>,
52    /// Ranking of this role
53    pub rank: Option<i64>,
54}
55
56/// Channel category
57#[derive(Serialize, Deserialize, Debug, Clone)]
58pub struct Category {
59    /// Unique ID for this category
60    pub id: String,
61    /// Title for this category
62    pub title: String,
63    /// Channels in this category
64    pub channels: Vec<String>,
65}
66
67/// System message channel assignments
68#[derive(Serialize, Deserialize, Debug, Clone, Default)]
69pub struct SystemMessageChannels {
70    /// ID of channel to send user join messages in
71    pub user_joined: Option<String>,
72    /// ID of channel to send user left messages in
73    pub user_left: Option<String>,
74    /// ID of channel to send user kicked messages in
75    pub user_kicked: Option<String>,
76    /// ID of channel to send user banned messages in
77    pub user_banned: Option<String>,
78}
79
80bitflags::bitflags! {
81    /// Server flag enum
82    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
83    pub struct ServerFlags: u64 {
84        const Verified = 1;
85        const Official = 2;
86    }
87}
88crate::impl_serde_bitflags!(ServerFlags);
89
90/// Representation of a server on Revolt
91#[derive(Deserialize, Debug, Clone)]
92pub struct Server {
93    /// Unique Id
94    #[serde(rename = "_id")]
95    pub id: String,
96    /// User id of the owner
97    pub owner: String,
98
99    /// Name of the server
100    pub name: String,
101    /// Description for the server
102    pub description: Option<String>,
103
104    /// Channels within this server
105    // ! FIXME: this may be redundant
106    pub channels: Vec<String>,
107    /// Categories for this server
108    pub categories: Option<Vec<Category>>,
109    /// Configuration for sending system event messages
110    pub system_messages: Option<SystemMessageChannels>,
111
112    /// Roles for this server
113    #[serde(default = "HashMap::<String, Role>::new")]
114    pub roles: HashMap<String, Role>,
115    /// Default set of server and channel permissions
116    pub default_permissions: Permission,
117
118    /// Icon attachment
119    pub icon: Option<Attachment>,
120    /// Banner attachment
121    pub banner: Option<Attachment>,
122
123    /// Enum of server flags
124    pub flags: Option<ServerFlags>,
125
126    /// Whether this server is flagged as not safe for work
127    #[serde(default)]
128    pub nsfw: bool,
129    /// Whether to enable analytics
130    #[serde(default)]
131    pub analytics: bool,
132    /// Whether this server should be publicly discoverable
133    #[serde(default)]
134    pub discoverable: bool,
135}
136
137/// Partial representation of a server on Revolt
138#[derive(Deserialize, Debug, Clone)]
139pub struct PartialServer {
140    /// User id of the owner
141    pub owner: Option<String>,
142
143    /// Name of the server
144    pub name: Option<String>,
145    /// Description for the server
146    pub description: Option<String>,
147
148    /// Channels within this server
149    // ! FIXME: this may be redundant
150    pub channels: Option<Vec<String>>,
151    /// Categories for this server
152    pub categories: Option<Vec<Category>>,
153    /// Configuration for sending system event messages
154    pub system_messages: Option<SystemMessageChannels>,
155
156    /// Roles for this server
157    pub roles: Option<HashMap<String, Role>>,
158    /// Default set of server and channel permissions
159    pub default_permissions: Option<Permission>,
160
161    /// Icon attachment
162    pub icon: Option<Attachment>,
163    /// Banner attachment
164    pub banner: Option<Attachment>,
165
166    /// Enum of server flags
167    pub flags: Option<ServerFlags>,
168
169    /// Whether this server is flagged as not safe for work
170    pub nsfw: Option<bool>,
171    /// Whether to enable analytics
172    pub analytics: Option<bool>,
173    /// Whether this server should be publicly discoverable
174    pub discoverable: Option<bool>,
175}
176
177/// Representation of a server ban
178#[derive(Deserialize, Debug, Clone)]
179pub struct ServerBan {
180    /// Unique member id
181    #[serde(rename = "_id")]
182    pub id: MemberCompositeKey,
183    /// Reason for ban creation
184    pub reason: Option<String>,
185}
186
187/// Banned user
188///
189/// Just enoguh user information to list bans.
190#[derive(Deserialize, Debug, Clone)]
191pub struct BannedUser {
192    /// Id of the banned user
193    #[serde(rename = "_id")]
194    pub id: String,
195    /// Username of the banned user
196    pub username: String,
197    /// Avatar of the banned user
198    pub avatar: Option<Attachment>,
199}
200
201/// Ban list
202#[derive(Deserialize, Debug, Clone)]
203pub struct BanList {
204    /// Users objects
205    pub users: Vec<BannedUser>,
206    /// Ban objects
207    pub bans: Vec<ServerBan>,
208}
209
210/// Optional fields on server object
211#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
212pub enum FieldsServer {
213    Description,
214    Categories,
215    SystemMessages,
216    Icon,
217    Banner,
218}
219
220/// Optional fields on server object
221#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
222pub enum FieldsRole {
223    Colour,
224}