1use serde::{Deserialize, Serialize};
2
3pub use stoat_models::v0::*;
4pub use stoat_permissions::{
5 ChannelPermission, DataPermissionsValue, Override, OverrideField, PermissionValue,
6 UserPermission,
7};
8
9use crate::Error;
10
11#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
12pub struct CaptchaFeature {
13 pub enabled: bool,
14 pub key: String,
15}
16
17#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
18pub struct Feature {
19 pub enabled: bool,
20 pub url: String,
21}
22
23#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
24pub struct VoiceNode {
25 pub name: String,
26 pub lat: f64,
27 pub lon: f64,
28 pub public_url: String,
29}
30
31#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
32pub struct VoiceFeature {
33 pub enabled: bool,
34 pub nodes: Vec<VoiceNode>,
35}
36
37#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
38pub struct StoatFeatures {
39 pub captcha: CaptchaFeature,
40 pub email: bool,
41 pub invite_only: bool,
42 pub autumn: Feature,
43 pub january: Feature,
44 pub livekit: VoiceFeature,
45}
46
47#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
48pub struct BuildInformation {
49 pub commit_sha: String,
50 pub commit_timestamp: String,
51 pub semver: String,
52 pub origin_url: String,
53 pub timestamp: String,
54}
55
56#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
57pub struct StoatConfig {
58 pub revolt: String,
59 pub features: StoatFeatures,
60 pub ws: String,
61 pub app: String,
62 pub vapid: String,
63 pub build: BuildInformation,
64}
65
66#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
67pub struct AutumnResponse {
68 pub id: String,
69}
70
71#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
72pub struct RatelimitFailure {
73 pub retry_after: u128,
74}
75
76#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
77#[serde(rename = "lowercase")]
78pub enum Tag {
79 Attachments,
80 Avatars,
81 Backgrounds,
82 Icons,
83 Banners,
84 Emojis,
85}
86
87impl Tag {
88 pub fn as_str(self) -> &'static str {
89 self.into()
90 }
91
92 pub fn to_string(self) -> String {
93 self.as_str().to_string()
94 }
95}
96
97impl Into<&'static str> for Tag {
98 fn into(self) -> &'static str {
99 match self {
100 Tag::Attachments => "attachments",
101 Tag::Avatars => "avatars",
102 Tag::Backgrounds => "backgrounds",
103 Tag::Icons => "icons",
104 Tag::Banners => "banners",
105 Tag::Emojis => "emojis",
106 }
107 }
108}
109
110impl TryFrom<&str> for Tag {
111 type Error = Error;
112
113 fn try_from(value: &str) -> Result<Self, Self::Error> {
114 match value {
115 "attachments" => Ok(Tag::Attachments),
116 "avatars" => Ok(Tag::Avatars),
117 "backgrounds" => Ok(Tag::Backgrounds),
118 "icons" => Ok(Tag::Icons),
119 "banners" => Ok(Tag::Banners),
120 "emojis" => Ok(Tag::Emojis),
121 _ => Err(Error::InvalidTag),
122 }
123 }
124}