1use super::File;
2
3use revolt_permissions::{Override, OverrideField};
4use std::collections::{HashMap, HashSet};
5
6#[cfg(feature = "rocket")]
7use rocket::FromForm;
8
9auto_derived!(
10 #[serde(tag = "channel_type")]
12 pub enum Channel {
13 SavedMessages {
15 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
17 id: String,
18 user: String,
20 },
21 DirectMessage {
23 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
25 id: String,
26
27 active: bool,
29 recipients: Vec<String>,
31 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
33 last_message_id: Option<String>,
34 },
35 Group {
37 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
39 id: String,
40
41 name: String,
43 owner: String,
45 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
47 description: Option<String>,
48 recipients: Vec<String>,
50
51 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
53 icon: Option<File>,
54 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
56 last_message_id: Option<String>,
57
58 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
61 permissions: Option<i64>,
62
63 #[cfg_attr(
65 feature = "serde",
66 serde(skip_serializing_if = "crate::if_false", default)
67 )]
68 nsfw: bool,
69 },
70 TextChannel {
72 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
74 id: String,
75 server: String,
77
78 name: String,
80 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
82 description: Option<String>,
83
84 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
86 icon: Option<File>,
87 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
89 last_message_id: Option<String>,
90
91 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
93 default_permissions: Option<OverrideField>,
94 #[cfg_attr(
96 feature = "serde",
97 serde(
98 default = "HashMap::<String, OverrideField>::new",
99 skip_serializing_if = "HashMap::<String, OverrideField>::is_empty"
100 )
101 )]
102 role_permissions: HashMap<String, OverrideField>,
103
104 #[cfg_attr(
106 feature = "serde",
107 serde(skip_serializing_if = "crate::if_false", default)
108 )]
109 nsfw: bool,
110 },
111 VoiceChannel {
113 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
115 id: String,
116 server: String,
118
119 name: String,
121 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
122 description: Option<String>,
124 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
126 icon: Option<File>,
127
128 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
130 default_permissions: Option<OverrideField>,
131 #[cfg_attr(
133 feature = "serde",
134 serde(
135 default = "HashMap::<String, OverrideField>::new",
136 skip_serializing_if = "HashMap::<String, OverrideField>::is_empty"
137 )
138 )]
139 role_permissions: HashMap<String, OverrideField>,
140
141 #[cfg_attr(
143 feature = "serde",
144 serde(skip_serializing_if = "crate::if_false", default)
145 )]
146 nsfw: bool,
147 },
148 }
149
150 #[derive(Default)]
152 pub struct PartialChannel {
153 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
154 pub name: Option<String>,
155 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
156 pub owner: Option<String>,
157 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
158 pub description: Option<String>,
159 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
160 pub icon: Option<File>,
161 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
162 pub nsfw: Option<bool>,
163 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
164 pub active: Option<bool>,
165 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
166 pub permissions: Option<i64>,
167 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
168 pub role_permissions: Option<HashMap<String, OverrideField>>,
169 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
170 pub default_permissions: Option<OverrideField>,
171 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
172 pub last_message_id: Option<String>,
173 }
174
175 pub enum FieldsChannel {
177 Description,
178 Icon,
179 DefaultPermissions,
180 }
181
182 #[cfg_attr(feature = "validator", derive(validator::Validate))]
184 pub struct DataEditChannel {
185 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
187 pub name: Option<String>,
188
189 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
191 pub description: Option<String>,
192
193 pub owner: Option<String>,
195
196 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
200 pub icon: Option<String>,
201
202 pub nsfw: Option<bool>,
204
205 pub archived: Option<bool>,
207
208 #[cfg_attr(feature = "serde", serde(default))]
210 pub remove: Option<Vec<FieldsChannel>>,
211 }
212
213 #[derive(Default)]
215 #[cfg_attr(feature = "validator", derive(validator::Validate))]
216 pub struct DataCreateGroup {
217 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
219 pub name: String,
220 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
222 pub description: Option<String>,
223 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
225 pub icon: Option<String>,
226 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 49)))]
230 #[serde(default)]
231 pub users: HashSet<String>,
232 #[serde(skip_serializing_if = "Option::is_none")]
234 pub nsfw: Option<bool>,
235 }
236
237 #[derive(Default)]
239 pub enum LegacyServerChannelType {
240 #[default]
242 Text,
243 Voice,
245 }
246
247 #[derive(Default)]
249 #[cfg_attr(feature = "validator", derive(validator::Validate))]
250 pub struct DataCreateServerChannel {
251 #[serde(rename = "type", default = "LegacyServerChannelType::default")]
253 pub channel_type: LegacyServerChannelType,
254 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
256 pub name: String,
257 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
259 pub description: Option<String>,
260 #[serde(skip_serializing_if = "Option::is_none")]
262 pub nsfw: Option<bool>,
263 }
264
265 #[serde(untagged)]
267 pub enum DataDefaultChannelPermissions {
268 Value {
269 permissions: u64,
271 },
272 Field {
273 permissions: Override,
275 },
276 }
277
278 pub struct DataSetRolePermissions {
280 pub permissions: Override,
282 }
283
284 #[cfg_attr(feature = "rocket", derive(FromForm))]
286 pub struct OptionsChannelDelete {
287 pub leave_silently: Option<bool>,
289 }
290
291 pub struct LegacyCreateVoiceUserResponse {
293 token: String,
295 }
296);
297
298impl Channel {
299 pub fn id(&self) -> &str {
301 match self {
302 Channel::DirectMessage { id, .. }
303 | Channel::Group { id, .. }
304 | Channel::SavedMessages { id, .. }
305 | Channel::TextChannel { id, .. }
306 | Channel::VoiceChannel { id, .. } => id,
307 }
308 }
309
310 pub fn name(&self) -> Option<&str> {
315 match self {
316 Channel::DirectMessage { .. } => None,
317 Channel::SavedMessages { .. } => Some("Saved Messages"),
318 Channel::TextChannel { name, .. }
319 | Channel::Group { name, .. }
320 | Channel::VoiceChannel { name, .. } => Some(name),
321 }
322 }
323}