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