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