]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
db81fce46a78457317204d383888903a13d5633d
[lemmy.git] / crates / api_common / src / site.rs
1 use lemmy_db_schema::newtypes::{CommunityId, PersonId};
2 use lemmy_db_views::{
3   comment_view::CommentView,
4   local_user_view::LocalUserSettingsView,
5   post_view::PostView,
6   site_view::SiteView,
7 };
8 use lemmy_db_views_actor::{
9   community_block_view::CommunityBlockView,
10   community_follower_view::CommunityFollowerView,
11   community_moderator_view::CommunityModeratorView,
12   community_view::CommunityView,
13   person_block_view::PersonBlockView,
14   person_view::PersonViewSafe,
15 };
16 use lemmy_db_views_moderator::{
17   mod_add_community_view::ModAddCommunityView,
18   mod_add_view::ModAddView,
19   mod_ban_from_community_view::ModBanFromCommunityView,
20   mod_ban_view::ModBanView,
21   mod_lock_post_view::ModLockPostView,
22   mod_remove_comment_view::ModRemoveCommentView,
23   mod_remove_community_view::ModRemoveCommunityView,
24   mod_remove_post_view::ModRemovePostView,
25   mod_sticky_post_view::ModStickyPostView,
26   mod_transfer_community_view::ModTransferCommunityView,
27 };
28 use serde::{Deserialize, Serialize};
29
30 #[derive(Serialize, Deserialize, Debug)]
31 pub struct Search {
32   pub q: String,
33   pub community_id: Option<CommunityId>,
34   pub community_name: Option<String>,
35   pub creator_id: Option<PersonId>,
36   pub type_: Option<String>,
37   pub sort: Option<String>,
38   pub listing_type: Option<String>,
39   pub page: Option<i64>,
40   pub limit: Option<i64>,
41   pub auth: Option<String>,
42 }
43
44 #[derive(Serialize, Deserialize, Debug)]
45 pub struct SearchResponse {
46   pub type_: String,
47   pub comments: Vec<CommentView>,
48   pub posts: Vec<PostView>,
49   pub communities: Vec<CommunityView>,
50   pub users: Vec<PersonViewSafe>,
51 }
52
53 #[derive(Serialize, Deserialize, Debug)]
54 pub struct ResolveObject {
55   pub q: String,
56   pub auth: Option<String>,
57 }
58
59 #[derive(Serialize, Deserialize, Default)]
60 pub struct ResolveObjectResponse {
61   pub comment: Option<CommentView>,
62   pub post: Option<PostView>,
63   pub community: Option<CommunityView>,
64   pub person: Option<PersonViewSafe>,
65 }
66
67 #[derive(Serialize, Deserialize)]
68 pub struct GetModlog {
69   pub mod_person_id: Option<PersonId>,
70   pub community_id: Option<CommunityId>,
71   pub page: Option<i64>,
72   pub limit: Option<i64>,
73 }
74
75 #[derive(Serialize, Deserialize)]
76 pub struct GetModlogResponse {
77   pub removed_posts: Vec<ModRemovePostView>,
78   pub locked_posts: Vec<ModLockPostView>,
79   pub stickied_posts: Vec<ModStickyPostView>,
80   pub removed_comments: Vec<ModRemoveCommentView>,
81   pub removed_communities: Vec<ModRemoveCommunityView>,
82   pub banned_from_community: Vec<ModBanFromCommunityView>,
83   pub banned: Vec<ModBanView>,
84   pub added_to_community: Vec<ModAddCommunityView>,
85   pub transferred_to_community: Vec<ModTransferCommunityView>,
86   pub added: Vec<ModAddView>,
87 }
88
89 #[derive(Serialize, Deserialize)]
90 pub struct CreateSite {
91   pub name: String,
92   pub sidebar: Option<String>,
93   pub description: Option<String>,
94   pub icon: Option<String>,
95   pub banner: Option<String>,
96   pub enable_downvotes: Option<bool>,
97   pub open_registration: Option<bool>,
98   pub enable_nsfw: Option<bool>,
99   pub community_creation_admin_only: Option<bool>,
100   pub auth: String,
101 }
102
103 #[derive(Serialize, Deserialize)]
104 pub struct EditSite {
105   pub name: Option<String>,
106   pub sidebar: Option<String>,
107   pub description: Option<String>,
108   pub icon: Option<String>,
109   pub banner: Option<String>,
110   pub enable_downvotes: Option<bool>,
111   pub open_registration: Option<bool>,
112   pub enable_nsfw: Option<bool>,
113   pub community_creation_admin_only: Option<bool>,
114   pub auth: String,
115 }
116
117 #[derive(Serialize, Deserialize)]
118 pub struct GetSite {
119   pub auth: Option<String>,
120 }
121
122 #[derive(Serialize, Deserialize, Clone)]
123 pub struct SiteResponse {
124   pub site_view: SiteView,
125 }
126
127 #[derive(Serialize, Deserialize)]
128 pub struct GetSiteResponse {
129   pub site_view: Option<SiteView>, // Because the site might not be set up yet
130   pub admins: Vec<PersonViewSafe>,
131   pub banned: Vec<PersonViewSafe>,
132   pub online: usize,
133   pub version: String,
134   pub my_user: Option<MyUserInfo>,
135   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
136 }
137
138 #[derive(Serialize, Deserialize)]
139 pub struct MyUserInfo {
140   pub local_user_view: LocalUserSettingsView,
141   pub follows: Vec<CommunityFollowerView>,
142   pub moderates: Vec<CommunityModeratorView>,
143   pub community_blocks: Vec<CommunityBlockView>,
144   pub person_blocks: Vec<PersonBlockView>,
145 }
146
147 #[derive(Serialize, Deserialize)]
148 pub struct TransferSite {
149   pub person_id: PersonId,
150   pub auth: String,
151 }
152
153 #[derive(Serialize, Deserialize)]
154 pub struct GetSiteConfig {
155   pub auth: String,
156 }
157
158 #[derive(Serialize, Deserialize)]
159 pub struct GetSiteConfigResponse {
160   pub config_hjson: String,
161 }
162
163 #[derive(Serialize, Deserialize)]
164 pub struct SaveSiteConfig {
165   pub config_hjson: String,
166   pub auth: String,
167 }
168
169 #[derive(Serialize, Deserialize)]
170 pub struct FederatedInstances {
171   pub linked: Vec<String>,
172   pub allowed: Option<Vec<String>>,
173   pub blocked: Option<Vec<String>>,
174 }