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 }
168
169 #[cfg_attr(feature = "validator", derive(validator::Validate))]
171 pub struct DataEditChannel {
172 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
174 pub name: Option<String>,
175
176 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
178 pub description: Option<String>,
179
180 pub owner: Option<String>,
182
183 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
187 pub icon: Option<String>,
188
189 pub nsfw: Option<bool>,
191
192 pub archived: Option<bool>,
194
195 pub voice: Option<VoiceInformation>,
197
198 #[cfg_attr(feature = "validator", validate(range(min = 0, max = 21600)))]
200 pub slowmode: Option<u64>,
201
202 #[cfg_attr(feature = "serde", serde(default))]
204 pub remove: Vec<FieldsChannel>,
205 }
206
207 #[derive(Default)]
209 #[cfg_attr(feature = "validator", derive(validator::Validate))]
210 pub struct DataCreateGroup {
211 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
213 pub name: String,
214 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
216 pub description: Option<String>,
217 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
219 pub icon: Option<String>,
220 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 49)))]
224 #[serde(default)]
225 pub users: HashSet<String>,
226 #[serde(skip_serializing_if = "Option::is_none")]
228 pub nsfw: Option<bool>,
229 }
230
231 #[derive(Default)]
233 pub enum LegacyServerChannelType {
234 #[default]
236 Text,
237 Voice,
239 }
240
241 #[derive(Default)]
243 #[cfg_attr(feature = "validator", derive(validator::Validate))]
244 pub struct DataCreateServerChannel {
245 #[serde(rename = "type", default = "LegacyServerChannelType::default")]
247 pub channel_type: LegacyServerChannelType,
248 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
250 pub name: String,
251 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
253 pub description: Option<String>,
254 #[serde(skip_serializing_if = "Option::is_none")]
256 pub nsfw: Option<bool>,
257
258 #[serde(skip_serializing_if = "Option::is_none")]
260 pub voice: Option<VoiceInformation>,
261 }
262
263 #[serde(untagged)]
265 pub enum DataDefaultChannelPermissions {
266 Value {
267 permissions: u64,
269 },
270 Field {
271 permissions: Override,
273 },
274 }
275
276 pub struct DataSetRolePermissions {
278 pub permissions: Override,
280 }
281
282 #[cfg_attr(feature = "rocket", derive(FromForm))]
284 pub struct OptionsChannelDelete {
285 pub leave_silently: Option<bool>,
287 }
288
289 pub struct CreateVoiceUserResponse {
291 pub token: String,
293 pub url: String,
295 }
296
297 pub struct ChannelVoiceState {
299 pub id: String,
300 pub participants: Vec<UserVoiceState>,
302 }
303
304 pub struct DataJoinCall {
306 pub node: Option<String>,
308 pub force_disconnect: Option<bool>,
312 pub recipients: Option<Vec<String>>,
316 }
317
318 pub struct ChannelSlowmode {
319 pub channel_id: String,
320 pub duration: u64,
321 pub retry_after: u64,
322 }
323);
324
325impl Channel {
326 pub fn id(&self) -> &str {
328 match self {
329 Channel::DirectMessage { id, .. }
330 | Channel::Group { id, .. }
331 | Channel::SavedMessages { id, .. }
332 | Channel::TextChannel { id, .. } => id,
333 }
334 }
335
336 pub fn name(&self) -> Option<&str> {
341 match self {
342 Channel::DirectMessage { .. } => None,
343 Channel::SavedMessages { .. } => Some("Saved Messages"),
344 Channel::TextChannel { name, .. } | Channel::Group { name, .. } => Some(name),
345 }
346 }
347}