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