]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
Adding diesel enums for SortType and ListingType (#2808)
[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
46 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
47 pub struct Search {
48   pub q: String,
49   pub community_id: Option<CommunityId>,
50   pub community_name: Option<String>,
51   pub creator_id: Option<PersonId>,
52   pub type_: Option<SearchType>,
53   pub sort: Option<SortType>,
54   pub listing_type: Option<ListingType>,
55   pub page: Option<i64>,
56   pub limit: Option<i64>,
57   pub auth: Option<Sensitive<String>>,
58 }
59
60 #[derive(Debug, Serialize, Deserialize, Clone)]
61 pub struct SearchResponse {
62   pub type_: String,
63   pub comments: Vec<CommentView>,
64   pub posts: Vec<PostView>,
65   pub communities: Vec<CommunityView>,
66   pub users: Vec<PersonView>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
70 pub struct ResolveObject {
71   pub q: String,
72   pub auth: Sensitive<String>,
73 }
74
75 #[derive(Debug, Serialize, Deserialize, Default)]
76 pub struct ResolveObjectResponse {
77   pub comment: Option<CommentView>,
78   pub post: Option<PostView>,
79   pub community: Option<CommunityView>,
80   pub person: Option<PersonView>,
81 }
82
83 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
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 auth: Option<Sensitive<String>>,
90   pub type_: Option<ModlogActionType>,
91   pub other_person_id: Option<PersonId>,
92 }
93
94 #[derive(Debug, Serialize, Deserialize, Clone)]
95 pub struct GetModlogResponse {
96   pub removed_posts: Vec<ModRemovePostView>,
97   pub locked_posts: Vec<ModLockPostView>,
98   pub featured_posts: Vec<ModFeaturePostView>,
99   pub removed_comments: Vec<ModRemoveCommentView>,
100   pub removed_communities: Vec<ModRemoveCommunityView>,
101   pub banned_from_community: Vec<ModBanFromCommunityView>,
102   pub banned: Vec<ModBanView>,
103   pub added_to_community: Vec<ModAddCommunityView>,
104   pub transferred_to_community: Vec<ModTransferCommunityView>,
105   pub added: Vec<ModAddView>,
106   pub admin_purged_persons: Vec<AdminPurgePersonView>,
107   pub admin_purged_communities: Vec<AdminPurgeCommunityView>,
108   pub admin_purged_posts: Vec<AdminPurgePostView>,
109   pub admin_purged_comments: Vec<AdminPurgeCommentView>,
110   pub hidden_communities: Vec<ModHideCommunityView>,
111 }
112
113 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
114 pub struct CreateSite {
115   pub name: String,
116   pub sidebar: Option<String>,
117   pub description: Option<String>,
118   pub icon: Option<String>,
119   pub banner: Option<String>,
120   pub enable_downvotes: Option<bool>,
121   pub enable_nsfw: Option<bool>,
122   pub community_creation_admin_only: Option<bool>,
123   pub require_email_verification: Option<bool>,
124   pub application_question: Option<String>,
125   pub private_instance: Option<bool>,
126   pub default_theme: Option<String>,
127   pub default_post_listing_type: Option<ListingType>,
128   pub legal_information: Option<String>,
129   pub application_email_admins: Option<bool>,
130   pub hide_modlog_mod_names: Option<bool>,
131   pub discussion_languages: Option<Vec<LanguageId>>,
132   pub slur_filter_regex: Option<String>,
133   pub actor_name_max_length: Option<i32>,
134   pub rate_limit_message: Option<i32>,
135   pub rate_limit_message_per_second: Option<i32>,
136   pub rate_limit_post: Option<i32>,
137   pub rate_limit_post_per_second: Option<i32>,
138   pub rate_limit_register: Option<i32>,
139   pub rate_limit_register_per_second: Option<i32>,
140   pub rate_limit_image: Option<i32>,
141   pub rate_limit_image_per_second: Option<i32>,
142   pub rate_limit_comment: Option<i32>,
143   pub rate_limit_comment_per_second: Option<i32>,
144   pub rate_limit_search: Option<i32>,
145   pub rate_limit_search_per_second: Option<i32>,
146   pub federation_enabled: Option<bool>,
147   pub federation_debug: Option<bool>,
148   pub federation_worker_count: Option<i32>,
149   pub captcha_enabled: Option<bool>,
150   pub captcha_difficulty: Option<String>,
151   pub allowed_instances: Option<Vec<String>>,
152   pub blocked_instances: Option<Vec<String>>,
153   pub taglines: Option<Vec<String>>,
154   pub registration_mode: Option<RegistrationMode>,
155   pub auth: Sensitive<String>,
156 }
157
158 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
159 pub struct EditSite {
160   pub name: Option<String>,
161   pub sidebar: Option<String>,
162   pub description: Option<String>,
163   pub icon: Option<String>,
164   pub banner: Option<String>,
165   pub enable_downvotes: Option<bool>,
166   pub enable_nsfw: Option<bool>,
167   pub community_creation_admin_only: Option<bool>,
168   pub require_email_verification: Option<bool>,
169   pub application_question: Option<String>,
170   pub private_instance: Option<bool>,
171   pub default_theme: Option<String>,
172   pub default_post_listing_type: Option<ListingType>,
173   pub legal_information: Option<String>,
174   pub application_email_admins: Option<bool>,
175   pub hide_modlog_mod_names: Option<bool>,
176   pub discussion_languages: Option<Vec<LanguageId>>,
177   pub slur_filter_regex: Option<String>,
178   pub actor_name_max_length: Option<i32>,
179   pub rate_limit_message: Option<i32>,
180   pub rate_limit_message_per_second: Option<i32>,
181   pub rate_limit_post: Option<i32>,
182   pub rate_limit_post_per_second: Option<i32>,
183   pub rate_limit_register: Option<i32>,
184   pub rate_limit_register_per_second: Option<i32>,
185   pub rate_limit_image: Option<i32>,
186   pub rate_limit_image_per_second: Option<i32>,
187   pub rate_limit_comment: Option<i32>,
188   pub rate_limit_comment_per_second: Option<i32>,
189   pub rate_limit_search: Option<i32>,
190   pub rate_limit_search_per_second: Option<i32>,
191   pub federation_enabled: Option<bool>,
192   pub federation_debug: Option<bool>,
193   pub federation_worker_count: Option<i32>,
194   pub captcha_enabled: Option<bool>,
195   pub captcha_difficulty: Option<String>,
196   pub allowed_instances: Option<Vec<String>>,
197   pub blocked_instances: Option<Vec<String>>,
198   pub taglines: Option<Vec<String>>,
199   pub registration_mode: Option<RegistrationMode>,
200   pub reports_email_admins: Option<bool>,
201   pub auth: Sensitive<String>,
202 }
203
204 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
205 pub struct GetSite {
206   pub auth: Option<Sensitive<String>>,
207 }
208
209 #[derive(Debug, Serialize, Deserialize, Clone)]
210 pub struct SiteResponse {
211   pub site_view: SiteView,
212 }
213
214 #[derive(Debug, Serialize, Deserialize, Clone)]
215 pub struct GetSiteResponse {
216   pub site_view: SiteView,
217   pub admins: Vec<PersonView>,
218   pub online: usize,
219   pub version: String,
220   pub my_user: Option<MyUserInfo>,
221   pub all_languages: Vec<Language>,
222   pub discussion_languages: Vec<LanguageId>,
223   pub taglines: Vec<Tagline>,
224   pub custom_emojis: Vec<CustomEmojiView>,
225 }
226
227 #[derive(Debug, Serialize, Deserialize, Clone)]
228 pub struct GetFederatedInstances {}
229
230 #[derive(Debug, Serialize, Deserialize, Clone)]
231 pub struct GetFederatedInstancesResponse {
232   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
233 }
234
235 #[derive(Debug, Serialize, Deserialize, Clone)]
236 pub struct MyUserInfo {
237   pub local_user_view: LocalUserView,
238   pub follows: Vec<CommunityFollowerView>,
239   pub moderates: Vec<CommunityModeratorView>,
240   pub community_blocks: Vec<CommunityBlockView>,
241   pub person_blocks: Vec<PersonBlockView>,
242   pub discussion_languages: Vec<LanguageId>,
243 }
244
245 #[derive(Debug, Serialize, Deserialize, Clone)]
246 pub struct LeaveAdmin {
247   pub auth: Sensitive<String>,
248 }
249
250 #[derive(Debug, Serialize, Deserialize, Clone)]
251 pub struct FederatedInstances {
252   pub linked: Vec<Instance>,
253   pub allowed: Option<Vec<Instance>>,
254   pub blocked: Option<Vec<Instance>>,
255 }
256
257 #[derive(Debug, Serialize, Deserialize, Clone)]
258 pub struct PurgePerson {
259   pub person_id: PersonId,
260   pub reason: Option<String>,
261   pub auth: String,
262 }
263
264 #[derive(Debug, Serialize, Deserialize, Clone)]
265 pub struct PurgeCommunity {
266   pub community_id: CommunityId,
267   pub reason: Option<String>,
268   pub auth: String,
269 }
270
271 #[derive(Debug, Serialize, Deserialize, Clone)]
272 pub struct PurgePost {
273   pub post_id: PostId,
274   pub reason: Option<String>,
275   pub auth: String,
276 }
277
278 #[derive(Debug, Serialize, Deserialize, Clone)]
279 pub struct PurgeComment {
280   pub comment_id: CommentId,
281   pub reason: Option<String>,
282   pub auth: String,
283 }
284
285 #[derive(Serialize, Deserialize)]
286 pub struct PurgeItemResponse {
287   pub success: bool,
288 }
289
290 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
291 pub struct ListRegistrationApplications {
292   /// Only shows the unread applications (IE those without an admin actor)
293   pub unread_only: Option<bool>,
294   pub page: Option<i64>,
295   pub limit: Option<i64>,
296   pub auth: String,
297 }
298
299 #[derive(Debug, Serialize, Deserialize, Clone)]
300 pub struct ListRegistrationApplicationsResponse {
301   pub registration_applications: Vec<RegistrationApplicationView>,
302 }
303
304 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
305 pub struct ApproveRegistrationApplication {
306   pub id: i32,
307   pub approve: bool,
308   pub deny_reason: Option<String>,
309   pub auth: String,
310 }
311
312 #[derive(Debug, Serialize, Deserialize, Clone)]
313 pub struct RegistrationApplicationResponse {
314   pub registration_application: RegistrationApplicationView,
315 }
316
317 #[derive(Debug, Serialize, Deserialize, Clone)]
318 pub struct GetUnreadRegistrationApplicationCount {
319   pub auth: String,
320 }
321
322 #[derive(Debug, Serialize, Deserialize, Clone)]
323 pub struct GetUnreadRegistrationApplicationCountResponse {
324   pub registration_applications: i64,
325 }