]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
Derive default for api request structs, move type enums (#2245)
[lemmy.git] / crates / api_common / src / person.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_views::structs::{CommentView, PostView, PrivateMessageView};
3 use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonMentionView, PersonViewSafe};
4 use serde::{Deserialize, Serialize};
5
6 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
7 pub struct Login {
8   pub username_or_email: Sensitive<String>,
9   pub password: Sensitive<String>,
10 }
11 use lemmy_db_schema::{
12   newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId},
13   SortType,
14 };
15
16 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
17 pub struct Register {
18   pub username: String,
19   pub password: Sensitive<String>,
20   pub password_verify: Sensitive<String>,
21   pub show_nsfw: bool,
22   /// email is mandatory if email verification is enabled on the server
23   pub email: Option<Sensitive<String>>,
24   pub captcha_uuid: Option<String>,
25   pub captcha_answer: Option<String>,
26   pub honeypot: Option<String>,
27   /// An answer is mandatory if require application is enabled on the server
28   pub answer: Option<String>,
29 }
30
31 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
32 pub struct GetCaptcha {}
33
34 #[derive(Debug, Serialize, Deserialize, Clone)]
35 pub struct GetCaptchaResponse {
36   pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
37 }
38
39 #[derive(Debug, Serialize, Deserialize, Clone)]
40 pub struct CaptchaResponse {
41   pub png: String, // A Base64 encoded png
42   pub wav: String, // A Base64 encoded wav audio
43   pub uuid: String,
44 }
45
46 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
47 pub struct SaveUserSettings {
48   pub show_nsfw: Option<bool>,
49   pub show_scores: Option<bool>,
50   pub theme: Option<String>,
51   pub default_sort_type: Option<i16>,
52   pub default_listing_type: Option<i16>,
53   pub lang: Option<String>,
54   pub avatar: Option<String>,
55   pub banner: Option<String>,
56   pub display_name: Option<String>,
57   pub email: Option<Sensitive<String>>,
58   pub bio: Option<String>,
59   pub matrix_user_id: Option<String>,
60   pub show_avatars: Option<bool>,
61   pub send_notifications_to_email: Option<bool>,
62   pub bot_account: Option<bool>,
63   pub show_bot_accounts: Option<bool>,
64   pub show_read_posts: Option<bool>,
65   pub show_new_post_notifs: Option<bool>,
66   pub auth: Sensitive<String>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
70 pub struct ChangePassword {
71   pub new_password: Sensitive<String>,
72   pub new_password_verify: Sensitive<String>,
73   pub old_password: Sensitive<String>,
74   pub auth: Sensitive<String>,
75 }
76
77 #[derive(Debug, Serialize, Deserialize, Clone)]
78 pub struct LoginResponse {
79   /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
80   pub jwt: Option<Sensitive<String>>,
81   pub registration_created: bool,
82   pub verify_email_sent: bool,
83 }
84
85 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
86 pub struct GetPersonDetails {
87   pub person_id: Option<PersonId>, // One of these two are required
88   /// Example: dessalines , or dessalines@xyz.tld
89   pub username: Option<String>,
90   pub sort: Option<SortType>,
91   pub page: Option<i64>,
92   pub limit: Option<i64>,
93   pub community_id: Option<CommunityId>,
94   pub saved_only: Option<bool>,
95   pub auth: Option<Sensitive<String>>,
96 }
97
98 #[derive(Debug, Serialize, Deserialize, Clone)]
99 pub struct GetPersonDetailsResponse {
100   pub person_view: PersonViewSafe,
101   pub comments: Vec<CommentView>,
102   pub posts: Vec<PostView>,
103   pub moderates: Vec<CommunityModeratorView>,
104 }
105
106 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
107 pub struct GetRepliesResponse {
108   pub replies: Vec<CommentView>,
109 }
110
111 #[derive(Debug, Serialize, Deserialize, Clone)]
112 pub struct GetPersonMentionsResponse {
113   pub mentions: Vec<PersonMentionView>,
114 }
115
116 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
117 pub struct MarkAllAsRead {
118   pub auth: Sensitive<String>,
119 }
120
121 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
122 pub struct AddAdmin {
123   pub person_id: PersonId,
124   pub added: bool,
125   pub auth: Sensitive<String>,
126 }
127
128 #[derive(Debug, Serialize, Deserialize, Clone)]
129 pub struct AddAdminResponse {
130   pub admins: Vec<PersonViewSafe>,
131 }
132
133 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
134 pub struct BanPerson {
135   pub person_id: PersonId,
136   pub ban: bool,
137   pub remove_data: Option<bool>,
138   pub reason: Option<String>,
139   pub expires: Option<i64>,
140   pub auth: Sensitive<String>,
141 }
142
143 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
144 pub struct GetBannedPersons {
145   pub auth: String,
146 }
147
148 #[derive(Debug, Serialize, Deserialize, Clone)]
149 pub struct BannedPersonsResponse {
150   pub banned: Vec<PersonViewSafe>,
151 }
152
153 #[derive(Debug, Serialize, Deserialize, Clone)]
154 pub struct BanPersonResponse {
155   pub person_view: PersonViewSafe,
156   pub banned: bool,
157 }
158
159 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
160 pub struct BlockPerson {
161   pub person_id: PersonId,
162   pub block: bool,
163   pub auth: Sensitive<String>,
164 }
165
166 #[derive(Debug, Serialize, Deserialize, Clone)]
167 pub struct BlockPersonResponse {
168   pub person_view: PersonViewSafe,
169   pub blocked: bool,
170 }
171
172 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
173 pub struct GetReplies {
174   pub sort: Option<SortType>,
175   pub page: Option<i64>,
176   pub limit: Option<i64>,
177   pub unread_only: Option<bool>,
178   pub auth: Sensitive<String>,
179 }
180
181 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
182 pub struct GetPersonMentions {
183   pub sort: Option<SortType>,
184   pub page: Option<i64>,
185   pub limit: Option<i64>,
186   pub unread_only: Option<bool>,
187   pub auth: Sensitive<String>,
188 }
189
190 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
191 pub struct MarkPersonMentionAsRead {
192   pub person_mention_id: PersonMentionId,
193   pub read: bool,
194   pub auth: Sensitive<String>,
195 }
196
197 #[derive(Debug, Serialize, Deserialize, Clone)]
198 pub struct PersonMentionResponse {
199   pub person_mention_view: PersonMentionView,
200 }
201
202 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
203 pub struct DeleteAccount {
204   pub password: Sensitive<String>,
205   pub auth: Sensitive<String>,
206 }
207
208 #[derive(Debug, Serialize, Deserialize, Clone)]
209 pub struct DeleteAccountResponse {}
210
211 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
212 pub struct PasswordReset {
213   pub email: Sensitive<String>,
214 }
215
216 #[derive(Debug, Serialize, Deserialize, Clone)]
217 pub struct PasswordResetResponse {}
218
219 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
220 pub struct PasswordChangeAfterReset {
221   pub token: Sensitive<String>,
222   pub password: Sensitive<String>,
223   pub password_verify: Sensitive<String>,
224 }
225
226 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
227 pub struct CreatePrivateMessage {
228   pub content: String,
229   pub recipient_id: PersonId,
230   pub auth: Sensitive<String>,
231 }
232
233 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
234 pub struct EditPrivateMessage {
235   pub private_message_id: PrivateMessageId,
236   pub content: String,
237   pub auth: Sensitive<String>,
238 }
239
240 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
241 pub struct DeletePrivateMessage {
242   pub private_message_id: PrivateMessageId,
243   pub deleted: bool,
244   pub auth: Sensitive<String>,
245 }
246
247 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
248 pub struct MarkPrivateMessageAsRead {
249   pub private_message_id: PrivateMessageId,
250   pub read: bool,
251   pub auth: Sensitive<String>,
252 }
253
254 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
255 pub struct GetPrivateMessages {
256   pub unread_only: Option<bool>,
257   pub page: Option<i64>,
258   pub limit: Option<i64>,
259   pub auth: Sensitive<String>,
260 }
261
262 #[derive(Debug, Serialize, Deserialize, Clone)]
263 pub struct PrivateMessagesResponse {
264   pub private_messages: Vec<PrivateMessageView>,
265 }
266
267 #[derive(Debug, Serialize, Deserialize, Clone)]
268 pub struct PrivateMessageResponse {
269   pub private_message_view: PrivateMessageView,
270 }
271
272 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
273 pub struct GetReportCount {
274   pub community_id: Option<CommunityId>,
275   pub auth: Sensitive<String>,
276 }
277
278 #[derive(Debug, Serialize, Deserialize, Clone)]
279 pub struct GetReportCountResponse {
280   pub community_id: Option<CommunityId>,
281   pub comment_reports: i64,
282   pub post_reports: i64,
283 }
284
285 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
286 pub struct GetUnreadCount {
287   pub auth: Sensitive<String>,
288 }
289
290 #[derive(Debug, Serialize, Deserialize, Clone)]
291 pub struct GetUnreadCountResponse {
292   pub replies: i64,
293   pub mentions: i64,
294   pub private_messages: i64,
295 }
296
297 #[derive(Serialize, Deserialize, Clone, Default)]
298 pub struct VerifyEmail {
299   pub token: String,
300 }
301
302 #[derive(Debug, Serialize, Deserialize, Clone)]
303 pub struct VerifyEmailResponse {}