]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / api_common / src / site.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
4   source::{instance::Instance, language::Language, tagline::Tagline},
5   ListingType, ModlogActionType, RegistrationMode, SearchType, SortType,
6 };
7 use lemmy_db_views::structs::{
8   CommentView, CustomEmojiView, LocalUserView, PostView, RegistrationApplicationView, SiteView,
9 };
10 use lemmy_db_views_actor::structs::{
11   CommunityBlockView, CommunityFollowerView, CommunityModeratorView, CommunityView,
12   PersonBlockView, PersonView,
13 };
14 use lemmy_db_views_moderator::structs::{
15   AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView,
16   ModAddCommunityView, ModAddView, ModBanFromCommunityView, ModBanView, ModFeaturePostView,
17   ModHideCommunityView, ModLockPostView, ModRemoveCommentView, ModRemoveCommunityView,
18   ModRemovePostView, ModTransferCommunityView,
19 };
20 use serde::{Deserialize, Serialize};
21 use serde_with::skip_serializing_none;
22 #[cfg(feature = "full")]
23 use ts_rs::TS;
24
25 #[skip_serializing_none]
26 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
27 #[cfg_attr(feature = "full", derive(TS))]
28 #[cfg_attr(feature = "full", ts(export))]
29 /// Searches the site, given a query string, and some optional filters.
30 pub struct Search {
31   pub q: String,
32   pub community_id: Option<CommunityId>,
33   pub community_name: Option<String>,
34   pub creator_id: Option<PersonId>,
35   pub type_: Option<SearchType>,
36   pub sort: Option<SortType>,
37   pub listing_type: Option<ListingType>,
38   pub page: Option<i64>,
39   pub limit: Option<i64>,
40   pub auth: Option<Sensitive<String>>,
41 }
42
43 #[derive(Debug, Serialize, Deserialize, Clone)]
44 #[cfg_attr(feature = "full", derive(TS))]
45 #[cfg_attr(feature = "full", ts(export))]
46 /// The search response, containing lists of the return type possibilities
47 // TODO this should be redone as a list of tagged enums
48 pub struct SearchResponse {
49   pub type_: SearchType,
50   pub comments: Vec<CommentView>,
51   pub posts: Vec<PostView>,
52   pub communities: Vec<CommunityView>,
53   pub users: Vec<PersonView>,
54 }
55
56 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
57 #[cfg_attr(feature = "full", derive(TS))]
58 #[cfg_attr(feature = "full", ts(export))]
59 /// Does an apub fetch for an object.
60 pub struct ResolveObject {
61   /// Can be the full url, or a shortened version like: !fediverse@lemmy.ml
62   pub q: String,
63   pub auth: Option<Sensitive<String>>,
64 }
65
66 #[skip_serializing_none]
67 #[derive(Debug, Serialize, Deserialize, Default)]
68 #[cfg_attr(feature = "full", derive(TS))]
69 #[cfg_attr(feature = "full", ts(export))]
70 // TODO Change this to an enum
71 /// The response of an apub object fetch.
72 pub struct ResolveObjectResponse {
73   pub comment: Option<CommentView>,
74   pub post: Option<PostView>,
75   pub community: Option<CommunityView>,
76   pub person: Option<PersonView>,
77 }
78
79 #[skip_serializing_none]
80 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
81 #[cfg_attr(feature = "full", derive(TS))]
82 #[cfg_attr(feature = "full", ts(export))]
83 /// Fetches the modlog.
84 pub struct GetModlog {
85   pub mod_person_id: Option<PersonId>,
86   pub community_id: Option<CommunityId>,
87   pub page: Option<i64>,
88   pub limit: Option<i64>,
89   pub type_: Option<ModlogActionType>,
90   pub other_person_id: Option<PersonId>,
91   pub auth: Option<Sensitive<String>>,
92 }
93
94 #[derive(Debug, Serialize, Deserialize, Clone)]
95 #[cfg_attr(feature = "full", derive(TS))]
96 #[cfg_attr(feature = "full", ts(export))]
97 /// The modlog fetch response.
98 // TODO this should be redone as a list of tagged enums
99 pub struct GetModlogResponse {
100   pub removed_posts: Vec<ModRemovePostView>,
101   pub locked_posts: Vec<ModLockPostView>,
102   pub featured_posts: Vec<ModFeaturePostView>,
103   pub removed_comments: Vec<ModRemoveCommentView>,
104   pub removed_communities: Vec<ModRemoveCommunityView>,
105   pub banned_from_community: Vec<ModBanFromCommunityView>,
106   pub banned: Vec<ModBanView>,
107   pub added_to_community: Vec<ModAddCommunityView>,
108   pub transferred_to_community: Vec<ModTransferCommunityView>,
109   pub added: Vec<ModAddView>,
110   pub admin_purged_persons: Vec<AdminPurgePersonView>,
111   pub admin_purged_communities: Vec<AdminPurgeCommunityView>,
112   pub admin_purged_posts: Vec<AdminPurgePostView>,
113   pub admin_purged_comments: Vec<AdminPurgeCommentView>,
114   pub hidden_communities: Vec<ModHideCommunityView>,
115 }
116
117 #[skip_serializing_none]
118 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
119 #[cfg_attr(feature = "full", derive(TS))]
120 #[cfg_attr(feature = "full", ts(export))]
121 /// Creates a site. Should be done after first running lemmy.
122 pub struct CreateSite {
123   pub name: String,
124   pub sidebar: Option<String>,
125   pub description: Option<String>,
126   pub icon: Option<String>,
127   pub banner: Option<String>,
128   pub enable_downvotes: Option<bool>,
129   pub enable_federated_downvotes: Option<bool>,
130   pub enable_nsfw: Option<bool>,
131   pub community_creation_admin_only: Option<bool>,
132   pub require_email_verification: Option<bool>,
133   pub application_question: Option<String>,
134   pub private_instance: Option<bool>,
135   pub default_theme: Option<String>,
136   pub default_post_listing_type: Option<ListingType>,
137   pub legal_information: Option<String>,
138   pub application_email_admins: Option<bool>,
139   pub hide_modlog_mod_names: Option<bool>,
140   pub discussion_languages: Option<Vec<LanguageId>>,
141   pub slur_filter_regex: Option<String>,
142   pub actor_name_max_length: Option<i32>,
143   pub rate_limit_message: Option<i32>,
144   pub rate_limit_message_per_second: Option<i32>,
145   pub rate_limit_post: Option<i32>,
146   pub rate_limit_post_per_second: Option<i32>,
147   pub rate_limit_register: Option<i32>,
148   pub rate_limit_register_per_second: Option<i32>,
149   pub rate_limit_image: Option<i32>,
150   pub rate_limit_image_per_second: Option<i32>,
151   pub rate_limit_comment: Option<i32>,
152   pub rate_limit_comment_per_second: Option<i32>,
153   pub rate_limit_search: Option<i32>,
154   pub rate_limit_search_per_second: Option<i32>,
155   pub federation_enabled: Option<bool>,
156   pub federation_debug: Option<bool>,
157   pub captcha_enabled: Option<bool>,
158   pub captcha_difficulty: Option<String>,
159   pub allowed_instances: Option<Vec<String>>,
160   pub blocked_instances: Option<Vec<String>>,
161   pub taglines: Option<Vec<String>>,
162   pub registration_mode: Option<RegistrationMode>,
163   pub auth: Sensitive<String>,
164 }
165
166 #[skip_serializing_none]
167 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
168 #[cfg_attr(feature = "full", derive(TS))]
169 #[cfg_attr(feature = "full", ts(export))]
170 /// Edits a site.
171 pub struct EditSite {
172   pub name: Option<String>,
173   pub sidebar: Option<String>,
174   /// A shorter, one line description of your site.
175   pub description: Option<String>,
176   /// A url for your site's icon.
177   pub icon: Option<String>,
178   /// A url for your site's banner.
179   pub banner: Option<String>,
180   /// Whether to enable downvotes.
181   pub enable_downvotes: Option<bool>,
182   /// Whether to allow downvotes from federated sites.
183   pub enable_federated_downvotes: Option<bool>,
184   /// Whether to enable NSFW.
185   pub enable_nsfw: Option<bool>,
186   /// Limits community creation to admins only.
187   pub community_creation_admin_only: Option<bool>,
188   /// Whether to require email verification.
189   pub require_email_verification: Option<bool>,
190   /// Your application question form. This is in markdown, and can be many questions.
191   pub application_question: Option<String>,
192   /// Whether your instance is public, or private.
193   pub private_instance: Option<bool>,
194   /// The default theme. Usually "browser"
195   pub default_theme: Option<String>,
196   pub default_post_listing_type: Option<ListingType>,
197   /// An optional page of legal information
198   pub legal_information: Option<String>,
199   /// Whether to email admins when receiving a new application.
200   pub application_email_admins: Option<bool>,
201   /// Whether to hide moderator names from the modlog.
202   pub hide_modlog_mod_names: Option<bool>,
203   /// A list of allowed discussion languages.
204   pub discussion_languages: Option<Vec<LanguageId>>,
205   /// A regex string of items to filter.
206   pub slur_filter_regex: Option<String>,
207   /// The max length of actor names.
208   pub actor_name_max_length: Option<i32>,
209   /// The number of messages allowed in a given time frame.
210   pub rate_limit_message: Option<i32>,
211   pub rate_limit_message_per_second: Option<i32>,
212   /// The number of posts allowed in a given time frame.
213   pub rate_limit_post: Option<i32>,
214   pub rate_limit_post_per_second: Option<i32>,
215   /// The number of registrations allowed in a given time frame.
216   pub rate_limit_register: Option<i32>,
217   pub rate_limit_register_per_second: Option<i32>,
218   /// The number of image uploads allowed in a given time frame.
219   pub rate_limit_image: Option<i32>,
220   pub rate_limit_image_per_second: Option<i32>,
221   /// The number of comments allowed in a given time frame.
222   pub rate_limit_comment: Option<i32>,
223   pub rate_limit_comment_per_second: Option<i32>,
224   /// The number of searches allowed in a given time frame.
225   pub rate_limit_search: Option<i32>,
226   pub rate_limit_search_per_second: Option<i32>,
227   /// Whether to enable federation.
228   pub federation_enabled: Option<bool>,
229   /// Enables federation debugging.
230   pub federation_debug: Option<bool>,
231   /// Whether to enable captchas for signups.
232   pub captcha_enabled: Option<bool>,
233   /// The captcha difficulty. Can be easy, medium, or hard
234   pub captcha_difficulty: Option<String>,
235   /// A list of allowed instances. If none are set, federation is open.
236   pub allowed_instances: Option<Vec<String>>,
237   /// A list of blocked instances.
238   pub blocked_instances: Option<Vec<String>>,
239   /// A list of taglines shown at the top of the front page.
240   pub taglines: Option<Vec<String>>,
241   pub registration_mode: Option<RegistrationMode>,
242   /// Whether to email admins for new reports.
243   pub reports_email_admins: Option<bool>,
244   pub auth: Sensitive<String>,
245 }
246
247 #[skip_serializing_none]
248 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
249 #[cfg_attr(feature = "full", derive(TS))]
250 #[cfg_attr(feature = "full", ts(export))]
251 /// Fetches the site.
252 pub struct GetSite {
253   pub auth: Option<Sensitive<String>>,
254 }
255
256 #[derive(Debug, Serialize, Deserialize, Clone)]
257 #[cfg_attr(feature = "full", derive(TS))]
258 #[cfg_attr(feature = "full", ts(export))]
259 /// The response for a site.
260 pub struct SiteResponse {
261   pub site_view: SiteView,
262   pub taglines: Vec<Tagline>,
263 }
264
265 #[skip_serializing_none]
266 #[derive(Debug, Serialize, Deserialize, Clone)]
267 #[cfg_attr(feature = "full", derive(TS))]
268 #[cfg_attr(feature = "full", ts(export))]
269 /// An expanded response for a site.
270 pub struct GetSiteResponse {
271   pub site_view: SiteView,
272   pub admins: Vec<PersonView>,
273   pub version: String,
274   pub my_user: Option<MyUserInfo>,
275   pub all_languages: Vec<Language>,
276   pub discussion_languages: Vec<LanguageId>,
277   /// A list of taglines shown at the top of the front page.
278   pub taglines: Vec<Tagline>,
279   /// A list of custom emojis your site supports.
280   pub custom_emojis: Vec<CustomEmojiView>,
281 }
282
283 #[skip_serializing_none]
284 #[derive(Debug, Serialize, Deserialize, Clone)]
285 #[cfg_attr(feature = "full", derive(TS))]
286 #[cfg_attr(feature = "full", ts(export))]
287 /// Fetches the federated instances for your site.
288 pub struct GetFederatedInstances {
289   pub auth: Option<Sensitive<String>>,
290 }
291
292 #[skip_serializing_none]
293 #[derive(Debug, Serialize, Deserialize, Clone)]
294 #[cfg_attr(feature = "full", derive(TS))]
295 #[cfg_attr(feature = "full", ts(export))]
296 /// A response of federated instances.
297 pub struct GetFederatedInstancesResponse {
298   /// Optional, because federation may be disabled.
299   pub federated_instances: Option<FederatedInstances>,
300 }
301
302 #[derive(Debug, Serialize, Deserialize, Clone)]
303 #[cfg_attr(feature = "full", derive(TS))]
304 #[cfg_attr(feature = "full", ts(export))]
305 /// Your user info.
306 pub struct MyUserInfo {
307   pub local_user_view: LocalUserView,
308   pub follows: Vec<CommunityFollowerView>,
309   pub moderates: Vec<CommunityModeratorView>,
310   pub community_blocks: Vec<CommunityBlockView>,
311   pub person_blocks: Vec<PersonBlockView>,
312   pub discussion_languages: Vec<LanguageId>,
313 }
314
315 #[derive(Debug, Serialize, Deserialize, Clone)]
316 #[cfg_attr(feature = "full", derive(TS))]
317 #[cfg_attr(feature = "full", ts(export))]
318 /// Leaves the admin team.
319 pub struct LeaveAdmin {
320   pub auth: Sensitive<String>,
321 }
322
323 #[derive(Debug, Serialize, Deserialize, Clone)]
324 #[cfg_attr(feature = "full", derive(TS))]
325 #[cfg_attr(feature = "full", ts(export))]
326 /// A list of federated instances.
327 pub struct FederatedInstances {
328   pub linked: Vec<Instance>,
329   pub allowed: Vec<Instance>,
330   pub blocked: Vec<Instance>,
331 }
332
333 #[skip_serializing_none]
334 #[derive(Debug, Serialize, Deserialize, Clone)]
335 #[cfg_attr(feature = "full", derive(TS))]
336 #[cfg_attr(feature = "full", ts(export))]
337 /// Purges a person from the database. This will delete all content attached to that person.
338 pub struct PurgePerson {
339   pub person_id: PersonId,
340   pub reason: Option<String>,
341   pub auth: Sensitive<String>,
342 }
343
344 #[skip_serializing_none]
345 #[derive(Debug, Serialize, Deserialize, Clone)]
346 #[cfg_attr(feature = "full", derive(TS))]
347 #[cfg_attr(feature = "full", ts(export))]
348 /// Purges a community from the database. This will delete all content attached to that community.
349 pub struct PurgeCommunity {
350   pub community_id: CommunityId,
351   pub reason: Option<String>,
352   pub auth: Sensitive<String>,
353 }
354
355 #[skip_serializing_none]
356 #[derive(Debug, Serialize, Deserialize, Clone)]
357 #[cfg_attr(feature = "full", derive(TS))]
358 #[cfg_attr(feature = "full", ts(export))]
359 /// Purges a post from the database. This will delete all content attached to that post.
360 pub struct PurgePost {
361   pub post_id: PostId,
362   pub reason: Option<String>,
363   pub auth: Sensitive<String>,
364 }
365
366 #[skip_serializing_none]
367 #[derive(Debug, Serialize, Deserialize, Clone)]
368 #[cfg_attr(feature = "full", derive(TS))]
369 #[cfg_attr(feature = "full", ts(export))]
370 /// Purges a comment from the database. This will delete all content attached to that comment.
371 pub struct PurgeComment {
372   pub comment_id: CommentId,
373   pub reason: Option<String>,
374   pub auth: Sensitive<String>,
375 }
376
377 #[derive(Serialize, Deserialize, Clone)]
378 #[cfg_attr(feature = "full", derive(TS))]
379 #[cfg_attr(feature = "full", ts(export))]
380 /// The response for purged items.
381 pub struct PurgeItemResponse {
382   pub success: bool,
383 }
384
385 #[skip_serializing_none]
386 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
387 #[cfg_attr(feature = "full", derive(TS))]
388 #[cfg_attr(feature = "full", ts(export))]
389 /// Fetches a list of registration applications.
390 pub struct ListRegistrationApplications {
391   /// Only shows the unread applications (IE those without an admin actor)
392   pub unread_only: Option<bool>,
393   pub page: Option<i64>,
394   pub limit: Option<i64>,
395   pub auth: Sensitive<String>,
396 }
397
398 #[derive(Debug, Serialize, Deserialize, Clone)]
399 #[cfg_attr(feature = "full", derive(TS))]
400 #[cfg_attr(feature = "full", ts(export))]
401 /// The list of registration applications.
402 pub struct ListRegistrationApplicationsResponse {
403   pub registration_applications: Vec<RegistrationApplicationView>,
404 }
405
406 #[skip_serializing_none]
407 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
408 #[cfg_attr(feature = "full", derive(TS))]
409 #[cfg_attr(feature = "full", ts(export))]
410 /// Approves a registration application.
411 pub struct ApproveRegistrationApplication {
412   pub id: i32,
413   pub approve: bool,
414   pub deny_reason: Option<String>,
415   pub auth: Sensitive<String>,
416 }
417
418 #[derive(Debug, Serialize, Deserialize, Clone)]
419 #[cfg_attr(feature = "full", derive(TS))]
420 #[cfg_attr(feature = "full", ts(export))]
421 /// The response of an action done to a registration application.
422 pub struct RegistrationApplicationResponse {
423   pub registration_application: RegistrationApplicationView,
424 }
425
426 #[derive(Debug, Serialize, Deserialize, Clone)]
427 #[cfg_attr(feature = "full", derive(TS))]
428 #[cfg_attr(feature = "full", ts(export))]
429 /// Gets a count of unread registration applications.
430 pub struct GetUnreadRegistrationApplicationCount {
431   pub auth: Sensitive<String>,
432 }
433
434 #[derive(Debug, Serialize, Deserialize, Clone)]
435 #[cfg_attr(feature = "full", derive(TS))]
436 #[cfg_attr(feature = "full", ts(export))]
437 /// The count of unread registration applications.
438 pub struct GetUnreadRegistrationApplicationCountResponse {
439   pub registration_applications: i64,
440 }