]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
add new flag to api (#3363)
[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 show_nsfw: Option<bool>,
80   pub page: Option<i64>,
81   pub limit: Option<i64>,
82   pub auth: Option<Sensitive<String>>,
83 }
84
85 #[derive(Debug, Serialize, Deserialize, Clone)]
86 #[cfg_attr(feature = "full", derive(TS))]
87 #[cfg_attr(feature = "full", ts(export))]
88 /// The response for listing communities.
89 pub struct ListCommunitiesResponse {
90   pub communities: Vec<CommunityView>,
91 }
92
93 #[skip_serializing_none]
94 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
95 #[cfg_attr(feature = "full", derive(TS))]
96 #[cfg_attr(feature = "full", ts(export))]
97 /// Ban a user from a community.
98 pub struct BanFromCommunity {
99   pub community_id: CommunityId,
100   pub person_id: PersonId,
101   pub ban: bool,
102   pub remove_data: Option<bool>,
103   pub reason: Option<String>,
104   pub expires: Option<i64>,
105   pub auth: Sensitive<String>,
106 }
107
108 #[derive(Debug, Serialize, Deserialize, Clone)]
109 #[cfg_attr(feature = "full", derive(TS))]
110 #[cfg_attr(feature = "full", ts(export))]
111 /// The response for banning a user from a community.
112 pub struct BanFromCommunityResponse {
113   pub person_view: PersonView,
114   pub banned: bool,
115 }
116
117 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
118 #[cfg_attr(feature = "full", derive(TS))]
119 #[cfg_attr(feature = "full", ts(export))]
120 /// Add a moderator to a community.
121 pub struct AddModToCommunity {
122   pub community_id: CommunityId,
123   pub person_id: PersonId,
124   pub added: bool,
125   pub auth: Sensitive<String>,
126 }
127
128 #[derive(Debug, Serialize, Deserialize, Clone)]
129 #[cfg_attr(feature = "full", derive(TS))]
130 #[cfg_attr(feature = "full", ts(export))]
131 /// The response of adding a moderator to a community.
132 pub struct AddModToCommunityResponse {
133   pub moderators: Vec<CommunityModeratorView>,
134 }
135
136 #[skip_serializing_none]
137 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
138 #[cfg_attr(feature = "full", derive(TS))]
139 #[cfg_attr(feature = "full", ts(export))]
140 /// Edit a community.
141 pub struct EditCommunity {
142   pub community_id: CommunityId,
143   /// A longer title.
144   pub title: Option<String>,
145   /// A longer sidebar, or description of your community, in markdown.
146   pub description: Option<String>,
147   /// An icon URL.
148   pub icon: Option<String>,
149   /// A banner URL.
150   pub banner: Option<String>,
151   /// Whether its an NSFW community.
152   pub nsfw: Option<bool>,
153   /// Whether to restrict posting only to moderators.
154   pub posting_restricted_to_mods: Option<bool>,
155   pub discussion_languages: Option<Vec<LanguageId>>,
156   pub auth: Sensitive<String>,
157 }
158
159 #[skip_serializing_none]
160 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
161 #[cfg_attr(feature = "full", derive(TS))]
162 #[cfg_attr(feature = "full", ts(export))]
163 /// Hide a community from the main view.
164 // TODO this should really be a part of edit community. And why does it contain a reason, that should be in the mod tables.
165 pub struct HideCommunity {
166   pub community_id: CommunityId,
167   pub hidden: bool,
168   pub reason: Option<String>,
169   pub auth: Sensitive<String>,
170 }
171
172 #[skip_serializing_none]
173 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
174 #[cfg_attr(feature = "full", derive(TS))]
175 #[cfg_attr(feature = "full", ts(export))]
176 /// Delete your own community.
177 pub struct DeleteCommunity {
178   pub community_id: CommunityId,
179   pub deleted: bool,
180   pub auth: Sensitive<String>,
181 }
182
183 #[skip_serializing_none]
184 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
185 #[cfg_attr(feature = "full", derive(TS))]
186 #[cfg_attr(feature = "full", ts(export))]
187 /// Remove a community (only doable by moderators).
188 pub struct RemoveCommunity {
189   pub community_id: CommunityId,
190   pub removed: bool,
191   pub reason: Option<String>,
192   pub expires: Option<i64>,
193   pub auth: Sensitive<String>,
194 }
195
196 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
197 #[cfg_attr(feature = "full", derive(TS))]
198 #[cfg_attr(feature = "full", ts(export))]
199 /// Follow / subscribe to a community.
200 pub struct FollowCommunity {
201   pub community_id: CommunityId,
202   pub follow: bool,
203   pub auth: Sensitive<String>,
204 }
205
206 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
207 #[cfg_attr(feature = "full", derive(TS))]
208 #[cfg_attr(feature = "full", ts(export))]
209 /// Block a community.
210 pub struct BlockCommunity {
211   pub community_id: CommunityId,
212   pub block: bool,
213   pub auth: Sensitive<String>,
214 }
215
216 #[skip_serializing_none]
217 #[derive(Debug, Serialize, Deserialize, Clone)]
218 #[cfg_attr(feature = "full", derive(TS))]
219 #[cfg_attr(feature = "full", ts(export))]
220 /// The block community response.
221 pub struct BlockCommunityResponse {
222   pub community_view: CommunityView,
223   pub blocked: bool,
224 }
225
226 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
227 #[cfg_attr(feature = "full", derive(TS))]
228 #[cfg_attr(feature = "full", ts(export))]
229 /// Transfer a community to a new owner.
230 pub struct TransferCommunity {
231   pub community_id: CommunityId,
232   pub person_id: PersonId,
233   pub auth: Sensitive<String>,
234 }