]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
e4619e64f6a7710f9788c9d0f636a6c052b5d621
[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::language::Language,
5   ListingType,
6   ModlogActionType,
7   SearchType,
8   SortType,
9 };
10 use lemmy_db_views::structs::{
11   CommentView,
12   LocalUserSettingsView,
13   PostView,
14   RegistrationApplicationView,
15   SiteView,
16 };
17 use lemmy_db_views_actor::structs::{
18   CommunityBlockView,
19   CommunityFollowerView,
20   CommunityModeratorView,
21   CommunityView,
22   PersonBlockView,
23   PersonViewSafe,
24 };
25 use lemmy_db_views_moderator::structs::{
26   AdminPurgeCommentView,
27   AdminPurgeCommunityView,
28   AdminPurgePersonView,
29   AdminPurgePostView,
30   ModAddCommunityView,
31   ModAddView,
32   ModBanFromCommunityView,
33   ModBanView,
34   ModHideCommunityView,
35   ModLockPostView,
36   ModRemoveCommentView,
37   ModRemoveCommunityView,
38   ModRemovePostView,
39   ModStickyPostView,
40   ModTransferCommunityView,
41 };
42 use serde::{Deserialize, Serialize};
43
44 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
45 pub struct Search {
46   pub q: String,
47   pub community_id: Option<CommunityId>,
48   pub community_name: Option<String>,
49   pub creator_id: Option<PersonId>,
50   pub type_: Option<SearchType>,
51   pub sort: Option<SortType>,
52   pub listing_type: Option<ListingType>,
53   pub page: Option<i64>,
54   pub limit: Option<i64>,
55   pub auth: Option<Sensitive<String>>,
56 }
57
58 #[derive(Debug, Serialize, Deserialize, Clone)]
59 pub struct SearchResponse {
60   pub type_: String,
61   pub comments: Vec<CommentView>,
62   pub posts: Vec<PostView>,
63   pub communities: Vec<CommunityView>,
64   pub users: Vec<PersonViewSafe>,
65 }
66
67 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
68 pub struct ResolveObject {
69   pub q: String,
70   pub auth: Option<Sensitive<String>>,
71 }
72
73 #[derive(Debug, Serialize, Deserialize, Default)]
74 pub struct ResolveObjectResponse {
75   pub comment: Option<CommentView>,
76   pub post: Option<PostView>,
77   pub community: Option<CommunityView>,
78   pub person: Option<PersonViewSafe>,
79 }
80
81 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
82 pub struct GetModlog {
83   pub mod_person_id: Option<PersonId>,
84   pub community_id: Option<CommunityId>,
85   pub page: Option<i64>,
86   pub limit: Option<i64>,
87   pub auth: Option<Sensitive<String>>,
88   pub type_: Option<ModlogActionType>,
89   pub other_person_id: Option<PersonId>,
90 }
91
92 #[derive(Debug, Serialize, Deserialize, Clone)]
93 pub struct GetModlogResponse {
94   pub removed_posts: Vec<ModRemovePostView>,
95   pub locked_posts: Vec<ModLockPostView>,
96   pub stickied_posts: Vec<ModStickyPostView>,
97   pub removed_comments: Vec<ModRemoveCommentView>,
98   pub removed_communities: Vec<ModRemoveCommunityView>,
99   pub banned_from_community: Vec<ModBanFromCommunityView>,
100   pub banned: Vec<ModBanView>,
101   pub added_to_community: Vec<ModAddCommunityView>,
102   pub transferred_to_community: Vec<ModTransferCommunityView>,
103   pub added: Vec<ModAddView>,
104   pub admin_purged_persons: Vec<AdminPurgePersonView>,
105   pub admin_purged_communities: Vec<AdminPurgeCommunityView>,
106   pub admin_purged_posts: Vec<AdminPurgePostView>,
107   pub admin_purged_comments: Vec<AdminPurgeCommentView>,
108   pub hidden_communities: Vec<ModHideCommunityView>,
109 }
110
111 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
112 pub struct CreateSite {
113   pub name: String,
114   pub sidebar: Option<String>,
115   pub description: Option<String>,
116   pub icon: Option<String>,
117   pub banner: Option<String>,
118   pub enable_downvotes: Option<bool>,
119   pub open_registration: Option<bool>,
120   pub enable_nsfw: Option<bool>,
121   pub community_creation_admin_only: Option<bool>,
122   pub require_email_verification: Option<bool>,
123   pub require_application: 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<String>,
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_strict_allowlist: Option<bool>,
149   pub federation_http_fetch_retry_limit: Option<i32>,
150   pub federation_worker_count: Option<i32>,
151   pub captcha_enabled: Option<bool>,
152   pub captcha_difficulty: Option<String>,
153   pub allowed_instances: Option<Vec<String>>,
154   pub blocked_instances: Option<Vec<String>>,
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 open_registration: Option<bool>,
167   pub enable_nsfw: Option<bool>,
168   pub community_creation_admin_only: Option<bool>,
169   pub require_email_verification: Option<bool>,
170   pub require_application: Option<bool>,
171   pub application_question: Option<String>,
172   pub private_instance: Option<bool>,
173   pub default_theme: Option<String>,
174   pub default_post_listing_type: Option<String>,
175   pub legal_information: Option<String>,
176   pub application_email_admins: Option<bool>,
177   pub hide_modlog_mod_names: Option<bool>,
178   pub discussion_languages: Option<Vec<LanguageId>>,
179   pub slur_filter_regex: Option<String>,
180   pub actor_name_max_length: Option<i32>,
181   pub rate_limit_message: Option<i32>,
182   pub rate_limit_message_per_second: Option<i32>,
183   pub rate_limit_post: Option<i32>,
184   pub rate_limit_post_per_second: Option<i32>,
185   pub rate_limit_register: Option<i32>,
186   pub rate_limit_register_per_second: Option<i32>,
187   pub rate_limit_image: Option<i32>,
188   pub rate_limit_image_per_second: Option<i32>,
189   pub rate_limit_comment: Option<i32>,
190   pub rate_limit_comment_per_second: Option<i32>,
191   pub rate_limit_search: Option<i32>,
192   pub rate_limit_search_per_second: Option<i32>,
193   pub federation_enabled: Option<bool>,
194   pub federation_debug: Option<bool>,
195   pub federation_strict_allowlist: Option<bool>,
196   pub federation_http_fetch_retry_limit: Option<i32>,
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 auth: Sensitive<String>,
203 }
204
205 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
206 pub struct GetSite {
207   pub auth: Option<Sensitive<String>>,
208 }
209
210 #[derive(Debug, Serialize, Deserialize, Clone)]
211 pub struct SiteResponse {
212   pub site_view: SiteView,
213 }
214
215 #[derive(Debug, Serialize, Deserialize, Clone)]
216 pub struct GetSiteResponse {
217   pub site_view: SiteView,
218   pub admins: Vec<PersonViewSafe>,
219   pub online: usize,
220   pub version: String,
221   pub my_user: Option<MyUserInfo>,
222   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
223   pub all_languages: Vec<Language>,
224   pub discussion_languages: Vec<LanguageId>,
225 }
226
227 #[derive(Debug, Serialize, Deserialize, Clone)]
228 pub struct MyUserInfo {
229   pub local_user_view: LocalUserSettingsView,
230   pub follows: Vec<CommunityFollowerView>,
231   pub moderates: Vec<CommunityModeratorView>,
232   pub community_blocks: Vec<CommunityBlockView>,
233   pub person_blocks: Vec<PersonBlockView>,
234   pub discussion_languages: Vec<Language>,
235 }
236
237 #[derive(Debug, Serialize, Deserialize, Clone)]
238 pub struct LeaveAdmin {
239   pub auth: Sensitive<String>,
240 }
241
242 #[derive(Debug, Serialize, Deserialize, Clone)]
243 pub struct FederatedInstances {
244   pub linked: Vec<String>,
245   pub allowed: Option<Vec<String>>,
246   pub blocked: Option<Vec<String>>,
247 }
248
249 #[derive(Debug, Serialize, Deserialize, Clone)]
250 pub struct PurgePerson {
251   pub person_id: PersonId,
252   pub reason: Option<String>,
253   pub auth: String,
254 }
255
256 #[derive(Debug, Serialize, Deserialize, Clone)]
257 pub struct PurgeCommunity {
258   pub community_id: CommunityId,
259   pub reason: Option<String>,
260   pub auth: String,
261 }
262
263 #[derive(Debug, Serialize, Deserialize, Clone)]
264 pub struct PurgePost {
265   pub post_id: PostId,
266   pub reason: Option<String>,
267   pub auth: String,
268 }
269
270 #[derive(Debug, Serialize, Deserialize, Clone)]
271 pub struct PurgeComment {
272   pub comment_id: CommentId,
273   pub reason: Option<String>,
274   pub auth: String,
275 }
276
277 #[derive(Serialize, Deserialize)]
278 pub struct PurgeItemResponse {
279   pub success: bool,
280 }
281
282 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
283 pub struct ListRegistrationApplications {
284   /// Only shows the unread applications (IE those without an admin actor)
285   pub unread_only: Option<bool>,
286   pub page: Option<i64>,
287   pub limit: Option<i64>,
288   pub auth: String,
289 }
290
291 #[derive(Debug, Serialize, Deserialize, Clone)]
292 pub struct ListRegistrationApplicationsResponse {
293   pub registration_applications: Vec<RegistrationApplicationView>,
294 }
295
296 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
297 pub struct ApproveRegistrationApplication {
298   pub id: i32,
299   pub approve: bool,
300   pub deny_reason: Option<String>,
301   pub auth: String,
302 }
303
304 #[derive(Debug, Serialize, Deserialize, Clone)]
305 pub struct RegistrationApplicationResponse {
306   pub registration_application: RegistrationApplicationView,
307 }
308
309 #[derive(Debug, Serialize, Deserialize, Clone)]
310 pub struct GetUnreadRegistrationApplicationCount {
311   pub auth: String,
312 }
313
314 #[derive(Debug, Serialize, Deserialize, Clone)]
315 pub struct GetUnreadRegistrationApplicationCountResponse {
316   pub registration_applications: i64,
317 }