1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//! # Subreddit Responses
use serde::Deserialize;

use crate::models::response::BasicListing;

/// SubredditResponse
#[derive(Debug, Deserialize)]
pub struct SubredditResponse {
    /// Should be "t5" for subreddits.
    pub kind: Option<String>,
    /// Data about subreddit.
    pub data: SubredditData,
}

/// accounts_active and active_user_count fields in `SubredditData`.
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum AccountsActive {
    /// The (approximate) number of users interacting with this subreddit over the past 15 minutes.
    /// this value may be "fuzzed" (see accounts_active_is_fuzzed).
    Number(u64),
    /// Reddit occasionally returns an empty array instead of an integer.
    Vector(Vec<u8>),
}

/// If the API user has user flair in this subreddit, and its user_flair_type is richtext,
/// this will be an array containing two string elements which define the user's flair.
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
pub struct RichtextFlair {
    /// contains the string text
    e: String,
    /// contains the literal string that comprises the user's flair.
    t: String,
}

/// SubredditData
#[derive(Debug, Deserialize)]
pub struct SubredditData {
    /// The HTML hex code of the API user's flair background color in this subreddit,
    /// if any. If the API user has no flair, or no background color is defined, this will be null.
    pub user_flair_background_color: Option<String>,
    /// This subreddit's configured "text to show on submission page," if any. If text is not configured,
    /// an empty string is returned.
    pub submit_text: Option<String>,
    //// The contents of submit_text converted to HTML entities.
    /// If no text has been configured, this will be null.
    pub submit_text_html: Option<String>,
    /// The text configured for this subreddit's "Custom label for submit text post button" option,
    /// if any. If no text has been configured, this will be null.
    pub submit_text_label: Option<String>,
    /// Whether or not submitting new links is restricted in this subreddit.
    /// This will be true when subreddit_type is restricted.
    pub restrict_posting: Option<bool>,
    /// Whether or not the API user is banned from participating in this subreddit.
    pub user_is_banned: Option<bool>,
    /// Whether or not this subreddit has the "allow free-form reports by users" option enabled.
    /// If the option is disabled, users must choose from a list of canned reporting reasons.
    pub free_form_reports: Option<bool>,
    /// Whether or not the API user has access to edit this subreddit's wiki.
    /// This will be true if one or more of the following conditions is satisfied:
    /// - The wiki is set to be editable by "anyone"
    /// - The wiki is set to "disabled" and the API user is a moderator
    /// - The wiki is set to "mod editing" and the API user is either a moderator or an approved contributor
    /// - Otherwise, this will be null.
    pub wiki_enabled: Option<bool>,
    /// Whether or not the API user has been muted in this subreddit.
    pub user_is_muted: Option<bool>,
    /// Whether or not the API user is allowed to set user flair in this subreddit.
    /// This will be true if:
    /// - the "Allow users to assign their own" user flair option is enabled
    /// - the API user is a moderator of this subreddit with the "flair" permission.
    /// - otherwise this will be null.
    pub user_can_flair_in_sr: Option<bool>,
    /// The base name of the subreddit with no decorators or adornments, e.g. funny.
    pub display_name: Option<String>,
    /// The name of the subreddit prefixed with its relative URI path, e.g. r/funny, or u/joe for user profile subreddits.
    pub display_name_prefixed: Option<String>,
    /// The URL to this subreddit's custom header image, if any.
    /// In the legacy web interface, this is the image that would appear in place of the default Snoo.
    /// If no custom header image is configured, this will be null.
    pub header_img: Option<String>,
    /// The title of this subreddit.
    pub title: Option<String>,
    /// Unknown
    pub allow_galleries: Option<bool>,
    /// If an icon_img has been configured for this subreddit,
    /// this will be an array containing two integer elements that define the image's width and height, e.g. `[256, 256]`.
    /// If no icon image is configured, this will be null.
    pub icon_size: Option<Vec<u64>>,
    /// The base36 internal Reddit identifier for this subreddit, e.g. 2qpqw.
    pub id: Option<String>,
    /// The HTML hex color code for this subreddit's primary color, if any. This corresponds to the "Base" theme color in the redesign web interface.
    /// If a color is not configured, an empty string is returned.
    pub primary_color: Option<String>,
    /// The (approximate) number of users interacting with this subreddit over the past 15 minutes.
    /// this value may be "fuzzed" (see accounts_active_is_fuzzed).
    /// Reddit occasionally returns an empty array instead of an integer. This isn't reproducible.
    /// This field is a duplicate of active_user_count.
    pub accounts_active: Option<AccountsActive>,
    /// The (approximate) number of users interacting with this subreddit over the past 15 minutes.
    /// this value may be "fuzzed" (see accounts_active_is_fuzzed).
    /// Reddit occasionally returns an empty array instead of an integer. This isn't reproducible.
    /// This field is a duplicate of accounts_active.
    pub active_user_count: Option<AccountsActive>,
    /// The URL to this subreddit's icon image, if any. In the redesign web interface,
    /// this icon is displayed in the "Community Details" portion of the sidebar, and on site listings (e.g. front page, /r/all)
    /// when the card layout is selected. If no icon image is configured, an empty string is returned.
    pub icon_img: Option<String>,
    /// Whether or not this subreddit exposes its traffic statistics to the public.
    pub public_traffic: Option<bool>,
    /// The number of accounts subscribed to this subreddit.
    pub subscribers: Option<u64>,
    /// If the API user has user flair in this subreddit, and its user_flair_type is richtext, this will be an array
    /// containing two string elements which define the user's flair. The first element, named e, contains the string text.
    /// The second element, named t, contains the literal string that comprises the user's flair. For example:
    /// [{"e":"text","t":"Proud Shitposter"}]
    pub user_flair_richtext: Option<Vec<RichtextFlair>>,
    /// Unknown. If set, the value appears to max out at 100.
    pub videostream_links_count: Option<u8>,
    /// The fullname identifier of this subreddit. This is a combination of the thing kind (t5) and the id,
    /// separated by an underscore, e.g. t5_2qh38
    pub name: Option<String>,
    /// Whether or not this subreddit is quarantined.
    /// This is a restricted property. To access a quarantined subreddit through this endpoint,
    /// the API user must have affirmatively clicked "continue" on its quarantine interstitial page at some point,
    /// and must be authenticated to the API with a valid access token.
    /// Other users will receive a 403 error when attempting to access a quarantined subreddit.
    pub quarantine: Option<bool>,
    /// Whether or not ads have been administratively suppressed in this subreddit.
    pub hide_ads: Option<bool>,
    /// Whether or not this subreddit has the "Enable emojis in this community" option enabled.
    pub emojis_enabled: Option<bool>,
    /// The advertiser categeory this subreddit falls under, if any has been assigned. If no value has been assigned,
    /// an empty string is returned.
    /// Observed values (as of August 2019) include:
    /// - Automotive
    /// - Business / Finance
    /// - College / University
    /// - Entertainment
    /// - Family & Youth
    /// - Games
    /// - Health
    /// - Lifestyles
    /// - Local
    /// - Retail
    /// - Sports
    /// - Technology
    /// - Travel
    pub advertiser_category: Option<String>,
    /// A description of this subreddit, as supplied by its moderator(s).
    /// If none has been configured, an empty string is returned.
    /// In both the legacy and redesign web interfaces, this text is used to build the <meta name="description"> tag.
    pub public_description: Option<String>,
    /// The "Minutes to hide comment scores" value configured for this subreddit.
    pub comment_score_hide_mins: Option<u64>,
    /// Unknown
    pub allow_predictions: Option<bool>,
    /// Whether or not the API user has added this subreddit to their favorites.
    pub user_has_favorited: Option<bool>,
    /// If the API user has user flair in this subreddit, and the user flair has been chosen from a predefined template,
    /// this will contain the 36-character UUID of the template. If user flair is not configured,
    /// or is an ad-hoc string with no predefined template, this will be null.
    pub user_flair_template_id: Option<bool>,
    /// The URL to this subreddit's community icon image, if any has been configured.
    /// If no value has been assigned, an empty string is returned.
    pub community_icon: Option<String>,
    /// The URL to this subreddit's banner background image, if any. This is the banner that displays on the desktop site.
    /// If no value has been assigned, an empty string is returned.
    pub banner_background_image: Option<String>,
    /// Whether or not this subreddit has the "enable marking posts as Original Content (OC) on the desktop redesign"
    /// option enabled.
    pub original_content_tag_enabled: Option<bool>,
    /// The contents of description converted to HTML entities. If no description has been configured, this will be null.
    pub description_html: Option<String>,
    /// Whether or not this subreddit allows tagging submissions as spoilers.
    pub spoilers_enabled: Option<bool>,
    /// The title configured for this subreddit's header_img, if any.
    /// If no header title is configured, this will be null.
    /// This field may be populated even if header_img is null, as an artifact from that field being previously set.
    pub header_title: Option<String>,
    /// If a header_img has been configured for this subreddit, this will be an array containing two integer elements
    /// that define the image's width and height, e.g. `[16, 16]`. If no header image is configured, this will be null.
    pub header_size: Option<Vec<u64>>,
    /// The CSS position of user flair in this subreddit, relative to the username,
    /// i.e. left or right. If user flair is not configured, an empty string is returned.
    pub user_flair_position: Option<String>,
    /// Whether or not this subreddit has the "mark all posts in this subreddit as
    /// Original Content (OC) on the desktop redesign" option enabled.
    pub all_original_content: Option<bool>,
    /// Whether or not this subreddit has custom menu tabs (submenu or link tabs) defined in the redesign web interface.
    pub has_menu_widget: Option<bool>,
    /// Whether or not this subreddit has enrolled in the new-style modmail interface.
    /// Newly created subreddits are automatically enrolled as of ~2018.
    /// This is a moderator-only property. To receive an accurate value, the API user must be a moderator of the subreddit,
    /// and must be authenticated to the API with a valid access token. Other users will receive a null value.
    pub is_enrolled_in_new_modmail: Option<bool>,
    /// The HTML hex color code for this subreddit's general theme color,
    /// if any is set. This corresponds to the "used as a thematic color for your subreddit on mobile" subreddit option.
    /// If no color is configured, an empty string is returned.
    pub key_color: Option<String>,
    /// Whether or not this subreddit allows users to assign flair to themselves.
    /// If false, only a moderator can assign flair to users.
    pub can_assign_user_flair: Option<bool>,
    /// The unix epoch timestamp at which this subreddit was created.
    /// This is provided as a float, but the fractional part is always zero.
    pub created: Option<f64>,
    /// A numeric value corresponding to the whitelist_status.
    pub wls: Option<u64>,
    /// Whether or not this subreddit has the "expand media previews on comments pages" option enabled.
    pub show_media_preview: Option<bool>,
    /// The type of links that can be submitted in this subreddit. This will typically be one of any, link, or self;
    /// some banned and employee-only subreddits have this value set to an empty string.
    pub submission_type: Option<String>,
    /// Whether or not the API user has subscribed to this subreddit.
    pub user_is_subscriber: Option<bool>,
    /// Whether or not this subreddit has the "Accepting new requests to post" option turned off.
    /// This is intended for subreddits with a subreddit_type of restricted
    pub disable_contributor_requests: Option<bool>,
    /// Unknown
    pub allow_videogifs: Option<bool>,
    /// If the API user has user flair in this subreddit, this will contain the flair type, either text or richtext.
    /// If user flair is not configured, this defaults to text.
    pub user_flair_type: Option<String>,
    /// Unknown
    pub allow_polls: Option<bool>,
    /// Whether or not this subreddit has the "collapse deleted and removed comments" option enabled.
    pub collapse_deleted_comments: Option<bool>,
    /// If "Custom sized emojis" has been configured for this subreddit,
    /// this will be an array containing two integer elements that define the emoji width and height, e.g. `[16, 16]`.
    /// If no custom emoji size is configured, this will be null.
    pub emojis_custom_size: Option<Vec<u64>>,
    /// The contents of public_description converted to HTML entities.
    /// If no public description has been configured, an empty string is returned.
    pub public_description_html: Option<String>,
    /// Whether or not this subreddit has the "allow video uploads" option enabled.
    pub allow_videos: Option<bool>,
    /// Whether or not this subreddit has the "Allow crossposting of posts" preference enabled.
    /// If crossposting is disabled, this will be null instead of false.
    pub is_crosspostable_subreddit: Option<bool>,
    /// The suggested comment sort order for this subreddit, if one has been set.
    /// If no sort order has been configured, this will be null.
    /// Observed values (as of August 2019) include: confidence, controversial, live, new, old, qa, random, top
    pub suggested_comment_sort: Option<String>,
    /// Whether or not users can assign flair to their own links in this subreddit.
    /// If false, only a moderator can assign flair to links.
    pub can_assign_link_flair: Option<bool>,
    /// For subreddits with a low number of subscribers,
    /// Reddit will artificially inflate the active user count in order to mitigate statistical inference attacks.
    pub accounts_active_is_fuzzed: Option<bool>,
    /// The CSS position of a link's flair in this subreddit, relative to the link, i.e. left or right.
    /// If link flair is not configured, an empty string is returned.
    pub link_flair_position: Option<String>,
    /// Whether or not the API user has opted to display their user flair in this subreddit
    /// This may be null if the API user has no user flair or has not indicated a display preference for it.
    pub user_sr_flair_enabled: Option<bool>,
    /// Whether or not user flair is enabled in this subreddit.
    /// This applies to the subreddit generally, not to the individual API user.
    pub user_flair_enabled_in_sr: Option<bool>,
    /// Whether or not this subreddit has the "allow this subreddit to be exposed to users who have
    /// shown intent or interest through discovery and onboarding" option enabled.
    pub allow_discovery: Option<bool>,
    /// Whether or not the API user allows this subreddit to display custom CSS (legacy terminology) or
    /// a community theme (redesign terminology) via the "allow subreddits to show me custom themes" preference.
    pub user_sr_theme_enabled: Option<bool>,
    /// Whether or not link flair is enabled in this subreddit.
    pub link_flair_enabled: Option<bool>,
    /// The access level applied to this subreddit. This will be one of public, restricted, private, or employees_only.
    /// This is a restricted property. To receive an accurate value for subreddits with a type other than public or restricted,
    /// the API user must have access to the subreddit, and must be authenticated to the API with a valid access token.
    /// Other users will receive a 403 error when attempting to access a private or employees_only subreddit.
    pub subreddit_type: Option<String>,
    /// Unknown. Observed values (as of August 2019) include: low
    /// This is a moderator-only property. To receive an accurate value, the API user must be a moderator of the subreddit,
    /// and must be authenticated to the API with a valid access token. Other users will receive a null value.
    pub notification_level: Option<String>,
    /// The URL to this subreddit's banner background image, if any. This is the banner that displays on the mobile site.
    /// If no value has been assigned, an empty string is returned.
    pub banner_img: Option<String>,
    /// If the API user has user flair in this subreddit, this will contain the literal string that comprises the user's flair.
    /// If user flair is not configured, this will be null.
    pub user_flair_text: Option<String>,
    /// The HTML hex color code for this subreddit's banner background color, if one has been set.
    /// If no value has been assigned, an empty string is returned.
    pub banner_background_color: Option<String>,
    /// Whether or not this subreddit has the "show thumbnail images of content" option enabled.
    pub show_media: Option<bool>,
    /// Whether or not the API user has been explicitly added as an approved user in this subreddit.
    pub user_is_contributor: Option<bool>,
    /// Whether or not this subreddit has the "viewers must be over eighteen years old" option enabled.
    pub over18: Option<bool>,
    /// A description of this subreddit as supplied by its moderator(s).
    pub description: Option<String>,
    /// The text configured for this subreddit's "Custom label for submit link button" option, if any.
    /// If no text has been configured, this will be null.
    pub submit_link_label: Option<String>,
    /// If the API user has user flair in this subreddit, this will contain a contrast label for their flair text,
    /// either light or dark.
    /// If the API user flair is not configured, this will be null.
    pub user_flair_text_color: Option<String>,
    /// Unknown
    pub restrict_commenting: Option<bool>,
    /// The CSS class corresponding to the API user's flair in this subreddit, if any.
    /// If the API user has no flair, or no CSS class is defined, this will be null.
    pub user_flair_css_class: Option<String>,
    /// Whether or not this subreddit has the "allow image uploads and links to image hosting sites" option enabled.
    pub allow_images: Option<bool>,
    /// The language/localization setting for this subreddit, if any. If no language is configured, an empty string is returned.
    pub lang: Option<String>,
    /// The advertising whitelist status of this subreddit, if set.
    /// If no whitelist status has been configured, an empty string is returned.
    /// Observed values (as of August 2019) include: all_ads, house_only, promo_adult_nsfw, promo_all, no_ads
    pub whitelist_status: Option<String>,
    /// The fully-qualified relative URI path to this subreddit, e.g. /r/HotPeppers, or /u/joe for user profile subreddits.
    pub url: Option<String>,
    /// The unix epoch timestamp reflecting the point 8 hours later than created. This is provided as a float,
    /// but the fractional part is always zero.
    pub created_utc: Option<f64>,
    /// If banner_img is set, this will be an array containing two integer elements that define the image's width and height,
    /// e.g. `[1280, 384]`. If no banner image is configured, this will be null.
    pub banner_size: Option<Vec<u64>>,
    /// The URL to this subreddit's mobile banner image. If no mobile banner is configured, an empty string is returned.
    pub mobile_banner_image: Option<String>,
    /// Whether or not the API user is a moderator of this subreddit.
    pub user_is_moderator: Option<bool>,
}

/// Subreddits
pub type SubredditsData = BasicListing<SubredditData>;