]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
eb520e29e89091122f19b6b061a7f6d56a16849c
[lemmy.git] / crates / api_common / src / site.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommunityId, 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 auth: Sensitive<String>,
129   pub hide_modlog_mod_names: Option<bool>,
130 }
131
132 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
133 pub struct EditSite {
134   pub name: Option<String>,
135   pub sidebar: Option<String>,
136   pub description: Option<String>,
137   pub icon: Option<String>,
138   pub banner: Option<String>,
139   pub enable_downvotes: Option<bool>,
140   pub open_registration: Option<bool>,
141   pub enable_nsfw: Option<bool>,
142   pub community_creation_admin_only: Option<bool>,
143   pub require_email_verification: Option<bool>,
144   pub require_application: Option<bool>,
145   pub application_question: Option<String>,
146   pub private_instance: Option<bool>,
147   pub default_theme: Option<String>,
148   pub default_post_listing_type: Option<String>,
149   pub legal_information: Option<String>,
150   pub auth: Sensitive<String>,
151   pub hide_modlog_mod_names: Option<bool>,
152 }
153
154 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
155 pub struct GetSite {
156   pub auth: Option<Sensitive<String>>,
157 }
158
159 #[derive(Debug, Serialize, Deserialize, Clone)]
160 pub struct SiteResponse {
161   pub site_view: SiteView,
162 }
163
164 #[derive(Debug, Serialize, Deserialize, Clone)]
165 pub struct GetSiteResponse {
166   pub site_view: Option<SiteView>, // Because the site might not be set up yet
167   pub admins: Vec<PersonViewSafe>,
168   pub online: usize,
169   pub version: String,
170   pub my_user: Option<MyUserInfo>,
171   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
172   pub all_languages: Vec<Language>,
173 }
174
175 #[derive(Debug, Serialize, Deserialize, Clone)]
176 pub struct MyUserInfo {
177   pub local_user_view: LocalUserSettingsView,
178   pub follows: Vec<CommunityFollowerView>,
179   pub moderates: Vec<CommunityModeratorView>,
180   pub community_blocks: Vec<CommunityBlockView>,
181   pub person_blocks: Vec<PersonBlockView>,
182   pub discussion_languages: Vec<Language>,
183 }
184
185 #[derive(Debug, Serialize, Deserialize, Clone)]
186 pub struct LeaveAdmin {
187   pub auth: Sensitive<String>,
188 }
189
190 #[derive(Debug, Serialize, Deserialize, Clone)]
191 pub struct FederatedInstances {
192   pub linked: Vec<String>,
193   pub allowed: Option<Vec<String>>,
194   pub blocked: Option<Vec<String>>,
195 }
196
197 #[derive(Debug, Serialize, Deserialize, Clone)]
198 pub struct PurgePerson {
199   pub person_id: PersonId,
200   pub reason: Option<String>,
201   pub auth: String,
202 }
203
204 #[derive(Debug, Serialize, Deserialize, Clone)]
205 pub struct PurgeCommunity {
206   pub community_id: CommunityId,
207   pub reason: Option<String>,
208   pub auth: String,
209 }
210
211 #[derive(Debug, Serialize, Deserialize, Clone)]
212 pub struct PurgePost {
213   pub post_id: PostId,
214   pub reason: Option<String>,
215   pub auth: String,
216 }
217
218 #[derive(Debug, Serialize, Deserialize, Clone)]
219 pub struct PurgeComment {
220   pub comment_id: CommentId,
221   pub reason: Option<String>,
222   pub auth: String,
223 }
224
225 #[derive(Serialize, Deserialize)]
226 pub struct PurgeItemResponse {
227   pub success: bool,
228 }
229
230 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
231 pub struct ListRegistrationApplications {
232   /// Only shows the unread applications (IE those without an admin actor)
233   pub unread_only: Option<bool>,
234   pub page: Option<i64>,
235   pub limit: Option<i64>,
236   pub auth: String,
237 }
238
239 #[derive(Debug, Serialize, Deserialize, Clone)]
240 pub struct ListRegistrationApplicationsResponse {
241   pub registration_applications: Vec<RegistrationApplicationView>,
242 }
243
244 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
245 pub struct ApproveRegistrationApplication {
246   pub id: i32,
247   pub approve: bool,
248   pub deny_reason: Option<String>,
249   pub auth: String,
250 }
251
252 #[derive(Debug, Serialize, Deserialize, Clone)]
253 pub struct RegistrationApplicationResponse {
254   pub registration_application: RegistrationApplicationView,
255 }
256
257 #[derive(Debug, Serialize, Deserialize, Clone)]
258 pub struct GetUnreadRegistrationApplicationCount {
259   pub auth: String,
260 }
261
262 #[derive(Debug, Serialize, Deserialize, Clone)]
263 pub struct GetUnreadRegistrationApplicationCountResponse {
264   pub registration_applications: i64,
265 }