Skip to main content

bsky_sdk/moderation/
labels.rs

1use super::error::Error;
2use super::types::*;
3use std::str::FromStr;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub(crate) enum KnownLabelValue {
7    ReservedHide,
8    ReservedWarn,
9    ReservedNoUnauthenticated,
10    Porn,
11    Sexual,
12    Nudity,
13    GraphicMedia,
14}
15
16impl FromStr for KnownLabelValue {
17    type Err = Error;
18
19    fn from_str(s: &str) -> Result<Self, Self::Err> {
20        match s {
21            "!hide" => Ok(Self::ReservedHide),
22            "!warn" => Ok(Self::ReservedWarn),
23            "!no-unauthenticated" => Ok(Self::ReservedNoUnauthenticated),
24            "porn" => Ok(Self::Porn),
25            "sexual" => Ok(Self::Sexual),
26            "nudity" => Ok(Self::Nudity),
27            "graphic-media" => Ok(Self::GraphicMedia),
28            _ => Err(Error::KnownLabelValue),
29        }
30    }
31}
32
33impl KnownLabelValue {
34    pub fn definition(&self) -> InterpretedLabelValueDefinition {
35        match self {
36            Self::ReservedHide => InterpretedLabelValueDefinition {
37                adult_only: false,
38                blurs: LabelValueDefinitionBlurs::Content,
39                default_setting: LabelPreference::Hide,
40                identifier: String::from("!hide"),
41                locales: Vec::new(),
42                severity: LabelValueDefinitionSeverity::Alert,
43                defined_by: None,
44                configurable: false,
45                flags: vec![LabelValueDefinitionFlag::NoOverride, LabelValueDefinitionFlag::NoSelf],
46                behaviors: InterpretedLabelValueDefinitionBehaviors {
47                    account: ModerationBehavior {
48                        profile_list: Some(ProfileListBehavior::Blur),
49                        profile_view: Some(ProfileViewBehavior::Blur),
50                        avatar: Some(AvatarBehavior::Blur),
51                        banner: Some(BannerBehavior::Blur),
52                        display_name: Some(DisplayNameBehavior::Blur),
53                        content_list: Some(ContentListBehavior::Blur),
54                        content_view: Some(ContentViewBehavior::Blur),
55                        ..Default::default()
56                    },
57                    profile: ModerationBehavior {
58                        avatar: Some(AvatarBehavior::Blur),
59                        banner: Some(BannerBehavior::Blur),
60                        display_name: Some(DisplayNameBehavior::Blur),
61                        ..Default::default()
62                    },
63                    content: ModerationBehavior {
64                        content_list: Some(ContentListBehavior::Blur),
65                        content_view: Some(ContentViewBehavior::Blur),
66                        ..Default::default()
67                    },
68                },
69            },
70            Self::ReservedWarn => InterpretedLabelValueDefinition {
71                adult_only: false,
72                blurs: LabelValueDefinitionBlurs::Content,
73                default_setting: LabelPreference::Warn,
74                identifier: String::from("!warn"),
75                locales: Vec::new(),
76                severity: LabelValueDefinitionSeverity::None,
77                defined_by: None,
78                configurable: false,
79                flags: vec![LabelValueDefinitionFlag::NoSelf],
80                behaviors: InterpretedLabelValueDefinitionBehaviors {
81                    account: ModerationBehavior {
82                        profile_list: Some(ProfileListBehavior::Blur),
83                        profile_view: Some(ProfileViewBehavior::Blur),
84                        avatar: Some(AvatarBehavior::Blur),
85                        banner: Some(BannerBehavior::Blur),
86                        content_list: Some(ContentListBehavior::Blur),
87                        content_view: Some(ContentViewBehavior::Blur),
88                        ..Default::default()
89                    },
90                    profile: ModerationBehavior {
91                        avatar: Some(AvatarBehavior::Blur),
92                        banner: Some(BannerBehavior::Blur),
93                        display_name: Some(DisplayNameBehavior::Blur),
94                        ..Default::default()
95                    },
96                    content: ModerationBehavior {
97                        content_list: Some(ContentListBehavior::Blur),
98                        content_view: Some(ContentViewBehavior::Blur),
99                        ..Default::default()
100                    },
101                },
102            },
103            Self::ReservedNoUnauthenticated => InterpretedLabelValueDefinition {
104                adult_only: false,
105                blurs: LabelValueDefinitionBlurs::Content,
106                default_setting: LabelPreference::Hide,
107                identifier: String::from("!no-unauthenticated"),
108                locales: Vec::new(),
109                severity: LabelValueDefinitionSeverity::None,
110                defined_by: None,
111                configurable: false,
112                flags: vec![
113                    LabelValueDefinitionFlag::NoOverride,
114                    LabelValueDefinitionFlag::Unauthed,
115                ],
116                behaviors: InterpretedLabelValueDefinitionBehaviors {
117                    account: ModerationBehavior {
118                        profile_list: Some(ProfileListBehavior::Blur),
119                        profile_view: Some(ProfileViewBehavior::Blur),
120                        avatar: Some(AvatarBehavior::Blur),
121                        banner: Some(BannerBehavior::Blur),
122                        display_name: Some(DisplayNameBehavior::Blur),
123                        content_list: Some(ContentListBehavior::Blur),
124                        content_view: Some(ContentViewBehavior::Blur),
125                        ..Default::default()
126                    },
127                    profile: ModerationBehavior {
128                        avatar: Some(AvatarBehavior::Blur),
129                        banner: Some(BannerBehavior::Blur),
130                        display_name: Some(DisplayNameBehavior::Blur),
131                        ..Default::default()
132                    },
133                    content: ModerationBehavior {
134                        content_list: Some(ContentListBehavior::Blur),
135                        content_view: Some(ContentViewBehavior::Blur),
136                        ..Default::default()
137                    },
138                },
139            },
140            Self::Porn => InterpretedLabelValueDefinition {
141                adult_only: false,
142                blurs: LabelValueDefinitionBlurs::Media,
143                default_setting: LabelPreference::Hide,
144                identifier: String::from("porn"),
145                locales: Vec::new(),
146                severity: LabelValueDefinitionSeverity::None,
147                defined_by: None,
148                configurable: true,
149                flags: vec![LabelValueDefinitionFlag::Adult],
150                behaviors: InterpretedLabelValueDefinitionBehaviors {
151                    account: ModerationBehavior {
152                        avatar: Some(AvatarBehavior::Blur),
153                        banner: Some(BannerBehavior::Blur),
154                        ..Default::default()
155                    },
156                    profile: ModerationBehavior {
157                        avatar: Some(AvatarBehavior::Blur),
158                        banner: Some(BannerBehavior::Blur),
159                        ..Default::default()
160                    },
161                    content: ModerationBehavior {
162                        content_media: Some(ContentMediaBehavior::Blur),
163                        ..Default::default()
164                    },
165                },
166            },
167            Self::Sexual => InterpretedLabelValueDefinition {
168                adult_only: false,
169                blurs: LabelValueDefinitionBlurs::Media,
170                default_setting: LabelPreference::Warn,
171                identifier: String::from("sexual"),
172                locales: Vec::new(),
173                severity: LabelValueDefinitionSeverity::None,
174                defined_by: None,
175                configurable: true,
176                flags: vec![LabelValueDefinitionFlag::Adult],
177                behaviors: InterpretedLabelValueDefinitionBehaviors {
178                    account: ModerationBehavior {
179                        avatar: Some(AvatarBehavior::Blur),
180                        banner: Some(BannerBehavior::Blur),
181                        ..Default::default()
182                    },
183                    profile: ModerationBehavior {
184                        avatar: Some(AvatarBehavior::Blur),
185                        banner: Some(BannerBehavior::Blur),
186                        ..Default::default()
187                    },
188                    content: ModerationBehavior {
189                        content_media: Some(ContentMediaBehavior::Blur),
190                        ..Default::default()
191                    },
192                },
193            },
194            Self::Nudity => InterpretedLabelValueDefinition {
195                adult_only: false,
196                blurs: LabelValueDefinitionBlurs::Media,
197                default_setting: LabelPreference::Ignore,
198                identifier: String::from("nudity"),
199                locales: Vec::new(),
200                severity: LabelValueDefinitionSeverity::None,
201                defined_by: None,
202                configurable: true,
203                flags: Vec::new(),
204                behaviors: InterpretedLabelValueDefinitionBehaviors {
205                    account: ModerationBehavior {
206                        avatar: Some(AvatarBehavior::Blur),
207                        banner: Some(BannerBehavior::Blur),
208                        ..Default::default()
209                    },
210                    profile: ModerationBehavior {
211                        avatar: Some(AvatarBehavior::Blur),
212                        banner: Some(BannerBehavior::Blur),
213                        ..Default::default()
214                    },
215                    content: ModerationBehavior {
216                        content_media: Some(ContentMediaBehavior::Blur),
217                        ..Default::default()
218                    },
219                },
220            },
221            Self::GraphicMedia => InterpretedLabelValueDefinition {
222                adult_only: false,
223                blurs: LabelValueDefinitionBlurs::Media,
224                default_setting: LabelPreference::Warn,
225                identifier: String::from("graphic-media"),
226                locales: Vec::new(),
227                severity: LabelValueDefinitionSeverity::None,
228                defined_by: None,
229                configurable: true,
230                flags: vec![LabelValueDefinitionFlag::Adult],
231                behaviors: InterpretedLabelValueDefinitionBehaviors {
232                    account: ModerationBehavior {
233                        avatar: Some(AvatarBehavior::Blur),
234                        banner: Some(BannerBehavior::Blur),
235                        ..Default::default()
236                    },
237                    profile: ModerationBehavior {
238                        avatar: Some(AvatarBehavior::Blur),
239                        banner: Some(BannerBehavior::Blur),
240                        ..Default::default()
241                    },
242                    content: ModerationBehavior {
243                        content_media: Some(ContentMediaBehavior::Blur),
244                        ..Default::default()
245                    },
246                },
247            },
248        }
249    }
250}