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