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