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 }
117
118 #[derive(Default)]
120 #[cfg_attr(feature = "validator", derive(validator::Validate))]
121 pub struct VoiceInformation {
122 #[cfg_attr(feature = "validator", validate(range(min = 1)))]
124 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
125 pub max_users: Option<usize>,
126 }
127
128 #[derive(Default)]
130 pub struct PartialChannel {
131 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
132 pub name: Option<String>,
133 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
134 pub owner: Option<String>,
135 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
136 pub description: Option<String>,
137 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
138 pub icon: Option<File>,
139 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
140 pub nsfw: Option<bool>,
141 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
142 pub active: Option<bool>,
143 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
144 pub permissions: Option<i64>,
145 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
146 pub role_permissions: Option<HashMap<String, OverrideField>>,
147 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
148 pub default_permissions: Option<OverrideField>,
149 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
150 pub last_message_id: Option<String>,
151 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
152 pub voice: Option<VoiceInformation>,
153 }
154
155 pub enum FieldsChannel {
157 Description,
158 Icon,
159 DefaultPermissions,
160 Voice,
161 }
162
163 #[cfg_attr(feature = "validator", derive(validator::Validate))]
165 pub struct DataEditChannel {
166 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
168 pub name: Option<String>,
169
170 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
172 pub description: Option<String>,
173
174 pub owner: Option<String>,
176
177 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
181 pub icon: Option<String>,
182
183 pub nsfw: Option<bool>,
185
186 pub archived: Option<bool>,
188
189 pub voice: Option<VoiceInformation>,
191
192 #[cfg_attr(feature = "serde", serde(default))]
194 pub remove: Vec<FieldsChannel>,
195 }
196
197 #[derive(Default)]
199 #[cfg_attr(feature = "validator", derive(validator::Validate))]
200 pub struct DataCreateGroup {
201 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
203 pub name: String,
204 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
206 pub description: Option<String>,
207 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
209 pub icon: Option<String>,
210 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 49)))]
214 #[serde(default)]
215 pub users: HashSet<String>,
216 #[serde(skip_serializing_if = "Option::is_none")]
218 pub nsfw: Option<bool>,
219 }
220
221 #[derive(Default)]
223 pub enum LegacyServerChannelType {
224 #[default]
226 Text,
227 Voice,
229 }
230
231 #[derive(Default)]
233 #[cfg_attr(feature = "validator", derive(validator::Validate))]
234 pub struct DataCreateServerChannel {
235 #[serde(rename = "type", default = "LegacyServerChannelType::default")]
237 pub channel_type: LegacyServerChannelType,
238 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
240 pub name: String,
241 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
243 pub description: Option<String>,
244 #[serde(skip_serializing_if = "Option::is_none")]
246 pub nsfw: Option<bool>,
247
248 #[serde(skip_serializing_if = "Option::is_none")]
250 pub voice: Option<VoiceInformation>,
251 }
252
253 #[serde(untagged)]
255 pub enum DataDefaultChannelPermissions {
256 Value {
257 permissions: u64,
259 },
260 Field {
261 permissions: Override,
263 },
264 }
265
266 pub struct DataSetRolePermissions {
268 pub permissions: Override,
270 }
271
272 #[cfg_attr(feature = "rocket", derive(FromForm))]
274 pub struct OptionsChannelDelete {
275 pub leave_silently: Option<bool>,
277 }
278
279 pub struct CreateVoiceUserResponse {
281 pub token: String,
283 pub url: String,
285 }
286
287 pub struct ChannelVoiceState {
289 pub id: String,
290 pub participants: Vec<UserVoiceState>,
292 }
293
294 pub struct DataJoinCall {
296 pub node: Option<String>,
298 pub force_disconnect: Option<bool>,
302 pub recipients: Option<Vec<String>>,
306 }
307);
308
309impl Channel {
310 pub fn id(&self) -> &str {
312 match self {
313 Channel::DirectMessage { id, .. }
314 | Channel::Group { id, .. }
315 | Channel::SavedMessages { id, .. }
316 | Channel::TextChannel { id, .. } => id,
317 }
318 }
319
320 pub fn name(&self) -> Option<&str> {
325 match self {
326 Channel::DirectMessage { .. } => None,
327 Channel::SavedMessages { .. } => Some("Saved Messages"),
328 Channel::TextChannel { name, .. } | Channel::Group { name, .. } => Some(name),
329 }
330 }
331}