]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
8a0e16a941a9e184c4b9e89174e70889c6868496
[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   ListingType,
5   SearchType,
6   SortType,
7 };
8 use lemmy_db_views::structs::{
9   CommentView,
10   LocalUserSettingsView,
11   PostView,
12   RegistrationApplicationView,
13   SiteView,
14 };
15 use lemmy_db_views_actor::structs::{
16   CommunityBlockView,
17   CommunityFollowerView,
18   CommunityModeratorView,
19   CommunityView,
20   PersonBlockView,
21   PersonViewSafe,
22 };
23 use lemmy_db_views_moderator::structs::{
24   AdminPurgeCommentView,
25   AdminPurgeCommunityView,
26   AdminPurgePersonView,
27   AdminPurgePostView,
28   ModAddCommunityView,
29   ModAddView,
30   ModBanFromCommunityView,
31   ModBanView,
32   ModHideCommunityView,
33   ModLockPostView,
34   ModRemoveCommentView,
35   ModRemoveCommunityView,
36   ModRemovePostView,
37   ModStickyPostView,
38   ModTransferCommunityView,
39 };
40 use serde::{Deserialize, Serialize};
41
42 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
43 pub struct Search {
44   pub q: String,
45   pub community_id: Option<CommunityId>,
46   pub community_name: Option<String>,
47   pub creator_id: Option<PersonId>,
48   pub type_: Option<SearchType>,
49   pub sort: Option<SortType>,
50   pub listing_type: Option<ListingType>,
51   pub page: Option<i64>,
52   pub limit: Option<i64>,
53   pub auth: Option<Sensitive<String>>,
54 }
55
56 #[derive(Debug, Serialize, Deserialize, Clone)]
57 pub struct SearchResponse {
58   pub type_: String,
59   pub comments: Vec<CommentView>,
60   pub posts: Vec<PostView>,
61   pub communities: Vec<CommunityView>,
62   pub users: Vec<PersonViewSafe>,
63 }
64
65 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
66 pub struct ResolveObject {
67   pub q: String,
68   pub auth: Option<Sensitive<String>>,
69 }
70
71 #[derive(Debug, Serialize, Deserialize, Default)]
72 pub struct ResolveObjectResponse {
73   pub comment: Option<CommentView>,
74   pub post: Option<PostView>,
75   pub community: Option<CommunityView>,
76   pub person: Option<PersonViewSafe>,
77 }
78
79 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
80 pub struct GetModlog {
81   pub mod_person_id: Option<PersonId>,
82   pub community_id: Option<CommunityId>,
83   pub page: Option<i64>,
84   pub limit: Option<i64>,
85   pub auth: Option<Sensitive<String>>,
86 }
87
88 #[derive(Debug, Serialize, Deserialize, Clone)]
89 pub struct GetModlogResponse {
90   pub removed_posts: Vec<ModRemovePostView>,
91   pub locked_posts: Vec<ModLockPostView>,
92   pub stickied_posts: Vec<ModStickyPostView>,
93   pub removed_comments: Vec<ModRemoveCommentView>,
94   pub removed_communities: Vec<ModRemoveCommunityView>,
95   pub banned_from_community: Vec<ModBanFromCommunityView>,
96   pub banned: Vec<ModBanView>,
97   pub added_to_community: Vec<ModAddCommunityView>,
98   pub transferred_to_community: Vec<ModTransferCommunityView>,
99   pub added: Vec<ModAddView>,
100   pub admin_purged_persons: Vec<AdminPurgePersonView>,
101   pub admin_purged_communities: Vec<AdminPurgeCommunityView>,
102   pub admin_purged_posts: Vec<AdminPurgePostView>,
103   pub admin_purged_comments: Vec<AdminPurgeCommentView>,
104   pub hidden_communities: Vec<ModHideCommunityView>,
105 }
106
107 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
108 pub struct CreateSite {
109   pub name: String,
110   pub sidebar: Option<String>,
111   pub description: Option<String>,
112   pub icon: Option<String>,
113   pub banner: Option<String>,
114   pub enable_downvotes: Option<bool>,
115   pub open_registration: Option<bool>,
116   pub enable_nsfw: Option<bool>,
117   pub community_creation_admin_only: Option<bool>,
118   pub require_email_verification: Option<bool>,
119   pub require_application: Option<bool>,
120   pub application_question: Option<String>,
121   pub private_instance: Option<bool>,
122   pub default_theme: Option<String>,
123   pub default_post_listing_type: Option<String>,
124   pub auth: Sensitive<String>,
125 }
126
127 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
128 pub struct EditSite {
129   pub name: Option<String>,
130   pub sidebar: Option<String>,
131   pub description: Option<String>,
132   pub icon: Option<String>,
133   pub banner: Option<String>,
134   pub enable_downvotes: Option<bool>,
135   pub open_registration: Option<bool>,
136   pub enable_nsfw: Option<bool>,
137   pub community_creation_admin_only: Option<bool>,
138   pub require_email_verification: Option<bool>,
139   pub require_application: Option<bool>,
140   pub application_question: Option<String>,
141   pub private_instance: Option<bool>,
142   pub default_theme: Option<String>,
143   pub default_post_listing_type: Option<String>,
144   pub legal_information: Option<String>,
145   pub auth: Sensitive<String>,
146 }
147
148 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
149 pub struct GetSite {
150   pub auth: Option<Sensitive<String>>,
151 }
152
153 #[derive(Debug, Serialize, Deserialize, Clone)]
154 pub struct SiteResponse {
155   pub site_view: SiteView,
156 }
157
158 #[derive(Debug, Serialize, Deserialize, Clone)]
159 pub struct GetSiteResponse {
160   pub site_view: Option<SiteView>, // Because the site might not be set up yet
161   pub admins: Vec<PersonViewSafe>,
162   pub online: usize,
163   pub version: String,
164   pub my_user: Option<MyUserInfo>,
165   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
166 }
167
168 #[derive(Debug, Serialize, Deserialize, Clone)]
169 pub struct MyUserInfo {
170   pub local_user_view: LocalUserSettingsView,
171   pub follows: Vec<CommunityFollowerView>,
172   pub moderates: Vec<CommunityModeratorView>,
173   pub community_blocks: Vec<CommunityBlockView>,
174   pub person_blocks: Vec<PersonBlockView>,
175 }
176
177 #[derive(Debug, Serialize, Deserialize, Clone)]
178 pub struct LeaveAdmin {
179   pub auth: Sensitive<String>,
180 }
181
182 #[derive(Debug, Serialize, Deserialize, Clone)]
183 pub struct FederatedInstances {
184   pub linked: Vec<String>,
185   pub allowed: Option<Vec<String>>,
186   pub blocked: Option<Vec<String>>,
187 }
188
189 #[derive(Debug, Serialize, Deserialize, Clone)]
190 pub struct PurgePerson {
191   pub person_id: PersonId,
192   pub reason: Option<String>,
193   pub auth: String,
194 }
195
196 #[derive(Debug, Serialize, Deserialize, Clone)]
197 pub struct PurgeCommunity {
198   pub community_id: CommunityId,
199   pub reason: Option<String>,
200   pub auth: String,
201 }
202
203 #[derive(Debug, Serialize, Deserialize, Clone)]
204 pub struct PurgePost {
205   pub post_id: PostId,
206   pub reason: Option<String>,
207   pub auth: String,
208 }
209
210 #[derive(Debug, Serialize, Deserialize, Clone)]
211 pub struct PurgeComment {
212   pub comment_id: CommentId,
213   pub reason: Option<String>,
214   pub auth: String,
215 }
216
217 #[derive(Serialize, Deserialize)]
218 pub struct PurgeItemResponse {
219   pub success: bool,
220 }
221
222 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
223 pub struct ListRegistrationApplications {
224   /// Only shows the unread applications (IE those without an admin actor)
225   pub unread_only: Option<bool>,
226   pub page: Option<i64>,
227   pub limit: Option<i64>,
228   pub auth: String,
229 }
230
231 #[derive(Debug, Serialize, Deserialize, Clone)]
232 pub struct ListRegistrationApplicationsResponse {
233   pub registration_applications: Vec<RegistrationApplicationView>,
234 }
235
236 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
237 pub struct ApproveRegistrationApplication {
238   pub id: i32,
239   pub approve: bool,
240   pub deny_reason: Option<String>,
241   pub auth: String,
242 }
243
244 #[derive(Debug, Serialize, Deserialize, Clone)]
245 pub struct RegistrationApplicationResponse {
246   pub registration_application: RegistrationApplicationView,
247 }
248
249 #[derive(Debug, Serialize, Deserialize, Clone)]
250 pub struct GetUnreadRegistrationApplicationCount {
251   pub auth: String,
252 }
253
254 #[derive(Debug, Serialize, Deserialize, Clone)]
255 pub struct GetUnreadRegistrationApplicationCountResponse {
256   pub registration_applications: i64,
257 }