]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
cb92d4c2e2afd11db552e4f1b05fb0f66529a703
[lemmy.git] / crates / api_common / src / community.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommunityId, LanguageId, PersonId},
4   source::site::Site,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
9 use serde::{Deserialize, Serialize};
10 use serde_with::skip_serializing_none;
11 #[cfg(feature = "full")]
12 use ts_rs::TS;
13
14 #[skip_serializing_none]
15 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
16 #[cfg_attr(feature = "full", derive(TS))]
17 #[cfg_attr(feature = "full", ts(export))]
18 /// Get a community. Must provide either an id, or a name.
19 pub struct GetCommunity {
20   pub id: Option<CommunityId>,
21   /// Example: star_trek , or star_trek@xyz.tld
22   pub name: Option<String>,
23   pub auth: Option<Sensitive<String>>,
24 }
25
26 #[skip_serializing_none]
27 #[derive(Debug, Serialize, Deserialize, Clone)]
28 #[cfg_attr(feature = "full", derive(TS))]
29 #[cfg_attr(feature = "full", ts(export))]
30 /// The community response.
31 pub struct GetCommunityResponse {
32   pub community_view: CommunityView,
33   pub site: Option<Site>,
34   pub moderators: Vec<CommunityModeratorView>,
35   pub discussion_languages: Vec<LanguageId>,
36 }
37
38 #[skip_serializing_none]
39 #[cfg_attr(feature = "full", derive(TS))]
40 #[cfg_attr(feature = "full", ts(export))]
41 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
42 /// Create a community.
43 pub struct CreateCommunity {
44   /// The unique name.
45   pub name: String,
46   /// A longer title.
47   pub title: String,
48   /// A longer sidebar, or description of your community, in markdown.
49   pub description: Option<String>,
50   /// An icon URL.
51   pub icon: Option<String>,
52   /// A banner URL.
53   pub banner: Option<String>,
54   /// Whether its an NSFW community.
55   pub nsfw: Option<bool>,
56   /// Whether to restrict posting only to moderators.
57   pub posting_restricted_to_mods: Option<bool>,
58   pub discussion_languages: Option<Vec<LanguageId>>,
59   pub auth: Sensitive<String>,
60 }
61
62 #[derive(Debug, Serialize, Deserialize, Clone)]
63 #[cfg_attr(feature = "full", derive(TS))]
64 #[cfg_attr(feature = "full", ts(export))]
65 /// A simple community response.
66 pub struct CommunityResponse {
67   pub community_view: CommunityView,
68   pub discussion_languages: Vec<LanguageId>,
69 }
70
71 #[skip_serializing_none]
72 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
73 #[cfg_attr(feature = "full", derive(TS))]
74 #[cfg_attr(feature = "full", ts(export))]
75 /// Fetches a list of communities.
76 pub struct ListCommunities {
77   pub type_: Option<ListingType>,
78   pub sort: Option<SortType>,
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 #[cfg_attr(feature = "full", derive(TS))]
86 #[cfg_attr(feature = "full", ts(export))]
87 /// The response for listing communities.
88 pub struct ListCommunitiesResponse {
89   pub communities: Vec<CommunityView>,
90 }
91
92 #[skip_serializing_none]
93 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
94 #[cfg_attr(feature = "full", derive(TS))]
95 #[cfg_attr(feature = "full", ts(export))]
96 /// Ban a user from a community.
97 pub struct BanFromCommunity {
98   pub community_id: CommunityId,
99   pub person_id: PersonId,
100   pub ban: bool,
101   pub remove_data: Option<bool>,
102   pub reason: Option<String>,
103   pub expires: Option<i64>,
104   pub auth: Sensitive<String>,
105 }
106
107 #[derive(Debug, Serialize, Deserialize, Clone)]
108 #[cfg_attr(feature = "full", derive(TS))]
109 #[cfg_attr(feature = "full", ts(export))]
110 /// The response for banning a user from a community.
111 pub struct BanFromCommunityResponse {
112   pub person_view: PersonView,
113   pub banned: bool,
114 }
115
116 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
117 #[cfg_attr(feature = "full", derive(TS))]
118 #[cfg_attr(feature = "full", ts(export))]
119 /// Add a moderator to a community.
120 pub struct AddModToCommunity {
121   pub community_id: CommunityId,
122   pub person_id: PersonId,
123   pub added: bool,
124   pub auth: Sensitive<String>,
125 }
126
127 #[derive(Debug, Serialize, Deserialize, Clone)]
128 #[cfg_attr(feature = "full", derive(TS))]
129 #[cfg_attr(feature = "full", ts(export))]
130 /// The response of adding a moderator to a community.
131 pub struct AddModToCommunityResponse {
132   pub moderators: Vec<CommunityModeratorView>,
133 }
134
135 #[skip_serializing_none]
136 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
137 #[cfg_attr(feature = "full", derive(TS))]
138 #[cfg_attr(feature = "full", ts(export))]
139 /// Edit a community.
140 pub struct EditCommunity {
141   pub community_id: CommunityId,
142   /// A longer title.
143   pub title: Option<String>,
144   /// A longer sidebar, or description of your community, in markdown.
145   pub description: Option<String>,
146   /// An icon URL.
147   pub icon: Option<String>,
148   /// A banner URL.
149   pub banner: Option<String>,
150   /// Whether its an NSFW community.
151   pub nsfw: Option<bool>,
152   /// Whether to restrict posting only to moderators.
153   pub posting_restricted_to_mods: Option<bool>,
154   pub discussion_languages: Option<Vec<LanguageId>>,
155   pub auth: Sensitive<String>,
156 }
157
158 #[skip_serializing_none]
159 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
160 #[cfg_attr(feature = "full", derive(TS))]
161 #[cfg_attr(feature = "full", ts(export))]
162 /// Hide a community from the main view.
163 // TODO this should really be a part of edit community. And why does it contain a reason, that should be in the mod tables.
164 pub struct HideCommunity {
165   pub community_id: CommunityId,
166   pub hidden: bool,
167   pub reason: Option<String>,
168   pub auth: Sensitive<String>,
169 }
170
171 #[skip_serializing_none]
172 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
173 #[cfg_attr(feature = "full", derive(TS))]
174 #[cfg_attr(feature = "full", ts(export))]
175 /// Delete your own community.
176 pub struct DeleteCommunity {
177   pub community_id: CommunityId,
178   pub deleted: bool,
179   pub auth: Sensitive<String>,
180 }
181
182 #[skip_serializing_none]
183 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
184 #[cfg_attr(feature = "full", derive(TS))]
185 #[cfg_attr(feature = "full", ts(export))]
186 /// Remove a community (only doable by moderators).
187 pub struct RemoveCommunity {
188   pub community_id: CommunityId,
189   pub removed: bool,
190   pub reason: Option<String>,
191   pub expires: Option<i64>,
192   pub auth: Sensitive<String>,
193 }
194
195 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
196 #[cfg_attr(feature = "full", derive(TS))]
197 #[cfg_attr(feature = "full", ts(export))]
198 /// Follow / subscribe to a community.
199 pub struct FollowCommunity {
200   pub community_id: CommunityId,
201   pub follow: bool,
202   pub auth: Sensitive<String>,
203 }
204
205 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
206 #[cfg_attr(feature = "full", derive(TS))]
207 #[cfg_attr(feature = "full", ts(export))]
208 /// Block a community.
209 pub struct BlockCommunity {
210   pub community_id: CommunityId,
211   pub block: bool,
212   pub auth: Sensitive<String>,
213 }
214
215 #[skip_serializing_none]
216 #[derive(Debug, Serialize, Deserialize, Clone)]
217 #[cfg_attr(feature = "full", derive(TS))]
218 #[cfg_attr(feature = "full", ts(export))]
219 /// The block community response.
220 pub struct BlockCommunityResponse {
221   pub community_view: CommunityView,
222   pub blocked: bool,
223 }
224
225 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
226 #[cfg_attr(feature = "full", derive(TS))]
227 #[cfg_attr(feature = "full", ts(export))]
228 /// Transfer a community to a new owner.
229 pub struct TransferCommunity {
230   pub community_id: CommunityId,
231   pub person_id: PersonId,
232   pub auth: Sensitive<String>,
233 }