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