1#![allow(deprecated)]
2use super::{File, UserVoiceState};
3
4use revolt_permissions::{Override, OverrideField};
5use std::collections::{HashMap, HashSet};
6
7#[cfg(feature = "rocket")]
8use rocket::FromForm;
9
10auto_derived!(
11 #[serde(tag = "channel_type")]
13 pub enum Channel {
14 SavedMessages {
16 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
18 id: String,
19 user: String,
21 },
22 DirectMessage {
24 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
26 id: String,
27
28 active: bool,
30 recipients: Vec<String>,
32 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
34 last_message_id: Option<String>,
35 },
36 Group {
38 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
40 id: String,
41
42 name: String,
44 owner: String,
46 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
48 description: Option<String>,
49 recipients: Vec<String>,
51
52 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
54 icon: Option<File>,
55 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
57 last_message_id: Option<String>,
58
59 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
62 permissions: Option<i64>,
63
64 #[cfg_attr(
66 feature = "serde",
67 serde(skip_serializing_if = "crate::if_false", default)
68 )]
69 nsfw: bool,
70 },
71 TextChannel {
73 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
75 id: String,
76 server: String,
78
79 name: String,
81 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
83 description: Option<String>,
84
85 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
87 icon: Option<File>,
88 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
90 last_message_id: Option<String>,
91
92 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
94 default_permissions: Option<OverrideField>,
95 #[cfg_attr(
97 feature = "serde",
98 serde(
99 default = "HashMap::<String, OverrideField>::new",
100 skip_serializing_if = "HashMap::<String, OverrideField>::is_empty"
101 )
102 )]
103 role_permissions: HashMap<String, OverrideField>,
104
105 #[cfg_attr(
107 feature = "serde",
108 serde(skip_serializing_if = "crate::if_false", default)
109 )]
110 nsfw: bool,
111
112 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
114 voice: Option<VoiceInformation>,
115
116 #[serde(skip_serializing_if = "Option::is_none")]
118 slowmode: Option<u64>,
119 },
120 }
121
122 #[derive(Default)]
124 #[cfg_attr(feature = "validator", derive(validator::Validate))]
125 pub struct VoiceInformation {
126 #[cfg_attr(feature = "validator", validate(range(min = 1)))]
128 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
129 pub max_users: Option<usize>,
130 }
131
132 #[derive(Default)]
134 pub struct PartialChannel {
135 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
136 pub name: Option<String>,
137 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
138 pub owner: Option<String>,
139 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
140 pub description: Option<String>,
141 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
142 pub icon: Option<File>,
143 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
144 pub nsfw: Option<bool>,
145 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
146 pub active: Option<bool>,
147 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
148 pub permissions: Option<i64>,
149 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
150 pub role_permissions: Option<HashMap<String, OverrideField>>,
151 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
152 pub default_permissions: Option<OverrideField>,
153 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
154 pub last_message_id: Option<String>,
155 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
156 pub voice: Option<VoiceInformation>,
157 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
158 pub slowmode: Option<u64>,
159 }
160
161 pub enum FieldsChannel {
163 Description,
164 Icon,
165 DefaultPermissions,
166 Voice,
167 Slowmode,
168 }
169
170 #[cfg_attr(feature = "validator", derive(validator::Validate))]
172 pub struct DataEditChannel {
173 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
175 pub name: Option<String>,
176
177 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
179 pub description: Option<String>,
180
181 pub owner: Option<String>,
183
184 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
188 pub icon: Option<String>,
189
190 pub nsfw: Option<bool>,
192
193 pub archived: Option<bool>,
195
196 pub voice: Option<VoiceInformation>,
198
199 #[cfg_attr(feature = "validator", validate(range(min = 0, max = 21600)))]
201 pub slowmode: Option<u64>,
202
203 #[cfg_attr(feature = "serde", serde(default))]
205 pub remove: Vec<FieldsChannel>,
206 }
207
208 #[derive(Default)]
210 #[cfg_attr(feature = "validator", derive(validator::Validate))]
211 pub struct DataCreateGroup {
212 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
214 pub name: String,
215 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
217 pub description: Option<String>,
218 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
220 pub icon: Option<String>,
221 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 49)))]
225 #[serde(default)]
226 pub users: HashSet<String>,
227 #[serde(skip_serializing_if = "Option::is_none")]
229 pub nsfw: Option<bool>,
230 }
231
232 #[derive(Default)]
234 pub enum LegacyServerChannelType {
235 #[default]
237 Text,
238 Voice,
240 }
241
242 #[derive(Default)]
244 #[cfg_attr(feature = "validator", derive(validator::Validate))]
245 pub struct DataCreateServerChannel {
246 #[serde(rename = "type", default = "LegacyServerChannelType::default")]
248 pub channel_type: LegacyServerChannelType,
249 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
251 pub name: String,
252 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
254 pub description: Option<String>,
255 #[serde(skip_serializing_if = "Option::is_none")]
257 pub nsfw: Option<bool>,
258
259 #[serde(skip_serializing_if = "Option::is_none")]
261 pub voice: Option<VoiceInformation>,
262 }
263
264 #[serde(untagged)]
266 pub enum DataDefaultChannelPermissions {
267 Value {
268 permissions: u64,
270 },
271 Field {
272 permissions: Override,
274 },
275 }
276
277 pub struct DataSetRolePermissions {
279 pub permissions: Override,
281 }
282
283 #[cfg_attr(feature = "rocket", derive(FromForm))]
285 pub struct OptionsChannelDelete {
286 pub leave_silently: Option<bool>,
288 }
289
290 pub struct CreateVoiceUserResponse {
292 pub token: String,
294 pub url: String,
296 }
297
298 pub struct ChannelVoiceState {
300 pub id: String,
301 pub participants: Vec<UserVoiceState>,
303 }
304
305 pub struct DataJoinCall {
307 pub node: Option<String>,
309 pub force_disconnect: Option<bool>,
313 pub recipients: Option<Vec<String>>,
317 }
318
319 pub struct ChannelSlowmode {
320 pub channel_id: String,
321 pub duration: u64,
322 pub retry_after: u64,
323 }
324);
325
326impl Channel {
327 pub fn id(&self) -> &str {
329 match self {
330 Channel::DirectMessage { id, .. }
331 | Channel::Group { id, .. }
332 | Channel::SavedMessages { id, .. }
333 | Channel::TextChannel { id, .. } => id,
334 }
335 }
336
337 pub fn name(&self) -> Option<&str> {
342 match self {
343 Channel::DirectMessage { .. } => None,
344 Channel::SavedMessages { .. } => Some("Saved Messages"),
345 Channel::TextChannel { name, .. } | Channel::Group { name, .. } => Some(name),
346 }
347 }
348}