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