]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
3c0f33d1c6c65fd5a2464c7b13f991f631e2314c
[lemmy.git] / crates / api_common / src / community.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommunityId, PersonId},
4   source::site::Site,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views_actor::structs::{
9   CommunityFollowerView,
10   CommunityModeratorView,
11   CommunityView,
12   PersonViewSafe,
13 };
14 use serde::{Deserialize, Serialize};
15
16 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
17 pub struct GetCommunity {
18   pub id: Option<CommunityId>,
19   /// Example: star_trek , or star_trek@xyz.tld
20   pub name: Option<String>,
21   pub auth: Option<Sensitive<String>>,
22 }
23
24 #[derive(Debug, Serialize, Deserialize, Clone)]
25 pub struct GetCommunityResponse {
26   pub community_view: CommunityView,
27   pub site: Option<Site>,
28   pub moderators: Vec<CommunityModeratorView>,
29   pub online: usize,
30 }
31
32 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
33 pub struct CreateCommunity {
34   pub name: String,
35   pub title: String,
36   pub description: Option<String>,
37   pub icon: Option<String>,
38   pub banner: Option<String>,
39   pub nsfw: Option<bool>,
40   pub posting_restricted_to_mods: Option<bool>,
41   pub auth: Sensitive<String>,
42 }
43
44 #[derive(Debug, Serialize, Deserialize, Clone)]
45 pub struct CommunityResponse {
46   pub community_view: CommunityView,
47 }
48
49 #[derive(Debug, Serialize, Deserialize, Clone)]
50 /// An unfollow will return None
51 pub struct FollowCommunityResponse {
52   pub community_follower_view: Option<CommunityFollowerView>,
53 }
54
55 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
56 pub struct ListCommunities {
57   pub type_: Option<ListingType>,
58   pub sort: Option<SortType>,
59   pub page: Option<i64>,
60   pub limit: Option<i64>,
61   pub auth: Option<Sensitive<String>>,
62 }
63
64 #[derive(Debug, Serialize, Deserialize, Clone)]
65 pub struct ListCommunitiesResponse {
66   pub communities: Vec<CommunityView>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
70 pub struct BanFromCommunity {
71   pub community_id: CommunityId,
72   pub person_id: PersonId,
73   pub ban: bool,
74   pub remove_data: Option<bool>,
75   pub reason: Option<String>,
76   pub expires: Option<i64>,
77   pub auth: Sensitive<String>,
78 }
79
80 #[derive(Debug, Serialize, Deserialize, Clone)]
81 pub struct BanFromCommunityResponse {
82   pub person_view: PersonViewSafe,
83   pub banned: bool,
84 }
85
86 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
87 pub struct AddModToCommunity {
88   pub community_id: CommunityId,
89   pub person_id: PersonId,
90   pub added: bool,
91   pub auth: Sensitive<String>,
92 }
93
94 #[derive(Debug, Serialize, Deserialize, Clone)]
95 pub struct AddModToCommunityResponse {
96   pub moderators: Vec<CommunityModeratorView>,
97 }
98
99 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
100 pub struct EditCommunity {
101   pub community_id: CommunityId,
102   pub title: Option<String>,
103   pub description: Option<String>,
104   pub icon: Option<String>,
105   pub banner: Option<String>,
106   pub nsfw: Option<bool>,
107   pub posting_restricted_to_mods: Option<bool>,
108   pub auth: Sensitive<String>,
109 }
110
111 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
112 pub struct HideCommunity {
113   pub community_id: CommunityId,
114   pub hidden: bool,
115   pub reason: Option<String>,
116   pub auth: Sensitive<String>,
117 }
118
119 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
120 pub struct DeleteCommunity {
121   pub community_id: CommunityId,
122   pub deleted: bool,
123   pub auth: Sensitive<String>,
124 }
125
126 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
127 pub struct RemoveCommunity {
128   pub community_id: CommunityId,
129   pub removed: bool,
130   pub reason: Option<String>,
131   pub expires: Option<i64>,
132   pub auth: Sensitive<String>,
133 }
134
135 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
136 pub struct FollowCommunity {
137   pub community_id: CommunityId,
138   pub follow: bool,
139   pub auth: Sensitive<String>,
140 }
141
142 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
143 pub struct BlockCommunity {
144   pub community_id: CommunityId,
145   pub block: bool,
146   pub auth: Sensitive<String>,
147 }
148
149 #[derive(Debug, Serialize, Deserialize, Clone)]
150 pub struct BlockCommunityResponse {
151   pub community_view: CommunityView,
152   pub blocked: bool,
153 }
154
155 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
156 pub struct TransferCommunity {
157   pub community_id: CommunityId,
158   pub person_id: PersonId,
159   pub auth: Sensitive<String>,
160 }