]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
Adding comments to all API related types. Fixes #2846 (#2848)
[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 online: usize,
36   pub discussion_languages: Vec<LanguageId>,
37   /// Default language used for new posts if none is specified, generated based on community and
38   /// user languages.
39   pub default_post_language: Option<LanguageId>,
40 }
41
42 #[skip_serializing_none]
43 #[cfg_attr(feature = "full", derive(TS))]
44 #[cfg_attr(feature = "full", ts(export))]
45 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
46 /// Create a community.
47 pub struct CreateCommunity {
48   /// The unique name.
49   pub name: String,
50   /// A longer title.
51   pub title: String,
52   /// A longer sidebar, or description of your community, in markdown.
53   pub description: Option<String>,
54   /// An icon URL.
55   pub icon: Option<String>,
56   /// A banner URL.
57   pub banner: Option<String>,
58   /// Whether its an NSFW community.
59   pub nsfw: Option<bool>,
60   /// Whether to restrict posting only to moderators.
61   pub posting_restricted_to_mods: Option<bool>,
62   pub discussion_languages: Option<Vec<LanguageId>>,
63   pub auth: Sensitive<String>,
64 }
65
66 #[derive(Debug, Serialize, Deserialize, Clone)]
67 #[cfg_attr(feature = "full", derive(TS))]
68 #[cfg_attr(feature = "full", ts(export))]
69 /// A simple community response.
70 pub struct CommunityResponse {
71   pub community_view: CommunityView,
72   pub discussion_languages: Vec<LanguageId>,
73 }
74
75 #[skip_serializing_none]
76 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
77 #[cfg_attr(feature = "full", derive(TS))]
78 #[cfg_attr(feature = "full", ts(export))]
79 /// Fetches a list of communities.
80 pub struct ListCommunities {
81   pub type_: Option<ListingType>,
82   pub sort: Option<SortType>,
83   pub page: Option<i64>,
84   pub limit: Option<i64>,
85   pub auth: Option<Sensitive<String>>,
86 }
87
88 #[derive(Debug, Serialize, Deserialize, Clone)]
89 #[cfg_attr(feature = "full", derive(TS))]
90 #[cfg_attr(feature = "full", ts(export))]
91 /// The response for listing communities.
92 pub struct ListCommunitiesResponse {
93   pub communities: Vec<CommunityView>,
94 }
95
96 #[skip_serializing_none]
97 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
98 #[cfg_attr(feature = "full", derive(TS))]
99 #[cfg_attr(feature = "full", ts(export))]
100 /// Ban a user from a community.
101 pub struct BanFromCommunity {
102   pub community_id: CommunityId,
103   pub person_id: PersonId,
104   pub ban: bool,
105   pub remove_data: Option<bool>,
106   pub reason: Option<String>,
107   pub expires: Option<i64>,
108   pub auth: Sensitive<String>,
109 }
110
111 #[derive(Debug, Serialize, Deserialize, Clone)]
112 #[cfg_attr(feature = "full", derive(TS))]
113 #[cfg_attr(feature = "full", ts(export))]
114 /// The response for banning a user from a community.
115 pub struct BanFromCommunityResponse {
116   pub person_view: PersonView,
117   pub banned: bool,
118 }
119
120 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
121 #[cfg_attr(feature = "full", derive(TS))]
122 #[cfg_attr(feature = "full", ts(export))]
123 /// Add a moderator to a community.
124 pub struct AddModToCommunity {
125   pub community_id: CommunityId,
126   pub person_id: PersonId,
127   pub added: bool,
128   pub auth: Sensitive<String>,
129 }
130
131 #[derive(Debug, Serialize, Deserialize, Clone)]
132 #[cfg_attr(feature = "full", derive(TS))]
133 #[cfg_attr(feature = "full", ts(export))]
134 /// The response of adding a moderator to a community.
135 pub struct AddModToCommunityResponse {
136   pub moderators: Vec<CommunityModeratorView>,
137 }
138
139 #[skip_serializing_none]
140 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
141 #[cfg_attr(feature = "full", derive(TS))]
142 #[cfg_attr(feature = "full", ts(export))]
143 /// Edit a community.
144 pub struct EditCommunity {
145   pub community_id: CommunityId,
146   /// A longer title.
147   pub title: Option<String>,
148   /// A longer sidebar, or description of your community, in markdown.
149   pub description: Option<String>,
150   /// An icon URL.
151   pub icon: Option<String>,
152   /// A banner URL.
153   pub banner: Option<String>,
154   /// Whether its an NSFW community.
155   pub nsfw: Option<bool>,
156   /// Whether to restrict posting only to moderators.
157   pub posting_restricted_to_mods: Option<bool>,
158   pub discussion_languages: Option<Vec<LanguageId>>,
159   pub auth: Sensitive<String>,
160 }
161
162 #[skip_serializing_none]
163 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
164 #[cfg_attr(feature = "full", derive(TS))]
165 #[cfg_attr(feature = "full", ts(export))]
166 /// Hide a community from the main view.
167 // TODO this should really be a part of edit community. And why does it contain a reason, that should be in the mod tables.
168 pub struct HideCommunity {
169   pub community_id: CommunityId,
170   pub hidden: bool,
171   pub reason: Option<String>,
172   pub auth: Sensitive<String>,
173 }
174
175 #[skip_serializing_none]
176 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
177 #[cfg_attr(feature = "full", derive(TS))]
178 #[cfg_attr(feature = "full", ts(export))]
179 /// Delete your own community.
180 pub struct DeleteCommunity {
181   pub community_id: CommunityId,
182   pub deleted: bool,
183   pub auth: Sensitive<String>,
184 }
185
186 #[skip_serializing_none]
187 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
188 #[cfg_attr(feature = "full", derive(TS))]
189 #[cfg_attr(feature = "full", ts(export))]
190 /// Remove a community (only doable by moderators).
191 pub struct RemoveCommunity {
192   pub community_id: CommunityId,
193   pub removed: bool,
194   pub reason: Option<String>,
195   pub expires: Option<i64>,
196   pub auth: Sensitive<String>,
197 }
198
199 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
200 #[cfg_attr(feature = "full", derive(TS))]
201 #[cfg_attr(feature = "full", ts(export))]
202 /// Follow / subscribe to a community.
203 pub struct FollowCommunity {
204   pub community_id: CommunityId,
205   pub follow: bool,
206   pub auth: Sensitive<String>,
207 }
208
209 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
210 #[cfg_attr(feature = "full", derive(TS))]
211 #[cfg_attr(feature = "full", ts(export))]
212 /// Block a community.
213 pub struct BlockCommunity {
214   pub community_id: CommunityId,
215   pub block: bool,
216   pub auth: Sensitive<String>,
217 }
218
219 #[skip_serializing_none]
220 #[derive(Debug, Serialize, Deserialize, Clone)]
221 #[cfg_attr(feature = "full", derive(TS))]
222 #[cfg_attr(feature = "full", ts(export))]
223 /// The block community response.
224 pub struct BlockCommunityResponse {
225   pub community_view: CommunityView,
226   pub blocked: bool,
227 }
228
229 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
230 #[cfg_attr(feature = "full", derive(TS))]
231 #[cfg_attr(feature = "full", ts(export))]
232 /// Transfer a community to a new owner.
233 pub struct TransferCommunity {
234   pub community_id: CommunityId,
235   pub person_id: PersonId,
236   pub auth: Sensitive<String>,
237 }