]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / api_common / src / person.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
4   CommentSortType,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views::structs::{CommentView, PostView};
9 use lemmy_db_views_actor::structs::{
10   CommentReplyView,
11   CommunityModeratorView,
12   PersonMentionView,
13   PersonView,
14 };
15 use serde::{Deserialize, Serialize};
16 use serde_with::skip_serializing_none;
17 #[cfg(feature = "full")]
18 use ts_rs::TS;
19
20 #[skip_serializing_none]
21 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
22 #[cfg_attr(feature = "full", derive(TS))]
23 #[cfg_attr(feature = "full", ts(export))]
24 /// Logging into lemmy.
25 pub struct Login {
26   pub username_or_email: Sensitive<String>,
27   pub password: Sensitive<String>,
28   /// May be required, if totp is enabled for their account.
29   pub totp_2fa_token: Option<String>,
30 }
31
32 #[skip_serializing_none]
33 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
34 #[cfg_attr(feature = "full", derive(TS))]
35 #[cfg_attr(feature = "full", ts(export))]
36 /// Register / Sign up to lemmy.
37 pub struct Register {
38   pub username: String,
39   pub password: Sensitive<String>,
40   pub password_verify: Sensitive<String>,
41   pub show_nsfw: bool,
42   /// email is mandatory if email verification is enabled on the server
43   pub email: Option<Sensitive<String>>,
44   /// The UUID of the captcha item.
45   pub captcha_uuid: Option<String>,
46   /// Your captcha answer.
47   pub captcha_answer: Option<String>,
48   /// A form field to trick signup bots. Should be None.
49   pub honeypot: Option<String>,
50   /// An answer is mandatory if require application is enabled on the server
51   pub answer: Option<String>,
52 }
53
54 #[skip_serializing_none]
55 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
56 #[cfg_attr(feature = "full", derive(TS))]
57 #[cfg_attr(feature = "full", ts(export))]
58 /// Fetches a Captcha item.
59 pub struct GetCaptcha {
60   pub auth: Option<Sensitive<String>>,
61 }
62
63 #[skip_serializing_none]
64 #[derive(Debug, Serialize, Deserialize, Clone)]
65 #[cfg_attr(feature = "full", derive(TS))]
66 #[cfg_attr(feature = "full", ts(export))]
67 /// A wrapper for the captcha response.
68 pub struct GetCaptchaResponse {
69   /// Will be None if captchas are disabled.
70   pub ok: Option<CaptchaResponse>,
71 }
72
73 #[derive(Debug, Serialize, Deserialize, Clone)]
74 #[cfg_attr(feature = "full", derive(TS))]
75 #[cfg_attr(feature = "full", ts(export))]
76 /// A captcha response.
77 pub struct CaptchaResponse {
78   /// A Base64 encoded png
79   pub png: String,
80   /// A Base64 encoded wav audio
81   pub wav: String,
82   /// The UUID for the captcha item.
83   pub uuid: String,
84 }
85
86 #[skip_serializing_none]
87 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
88 #[cfg_attr(feature = "full", derive(TS))]
89 #[cfg_attr(feature = "full", ts(export))]
90 /// Saves settings for your user.
91 pub struct SaveUserSettings {
92   /// Show nsfw posts.
93   pub show_nsfw: Option<bool>,
94   pub blur_nsfw: Option<bool>,
95   pub auto_expand: Option<bool>,
96   /// Show post and comment scores.
97   pub show_scores: Option<bool>,
98   /// Your user's theme.
99   pub theme: Option<String>,
100   pub default_sort_type: Option<SortType>,
101   pub default_listing_type: Option<ListingType>,
102   /// The language of the lemmy interface
103   pub interface_language: Option<String>,
104   /// A URL for your avatar.
105   pub avatar: Option<String>,
106   /// A URL for your banner.
107   pub banner: Option<String>,
108   /// Your display name, which can contain strange characters, and does not need to be unique.
109   pub display_name: Option<String>,
110   /// Your email.
111   pub email: Option<Sensitive<String>>,
112   /// Your bio / info, in markdown.
113   pub bio: Option<String>,
114   /// Your matrix user id. Ex: @my_user:matrix.org
115   pub matrix_user_id: Option<String>,
116   /// Whether to show or hide avatars.
117   pub show_avatars: Option<bool>,
118   /// Sends notifications to your email.
119   pub send_notifications_to_email: Option<bool>,
120   /// Whether this account is a bot account. Users can hide these accounts easily if they wish.
121   pub bot_account: Option<bool>,
122   /// Whether to show bot accounts.
123   pub show_bot_accounts: Option<bool>,
124   /// Whether to show read posts.
125   pub show_read_posts: Option<bool>,
126   /// Whether to show notifications for new posts.
127   // TODO notifs need to be reworked.
128   pub show_new_post_notifs: Option<bool>,
129   /// A list of languages you are able to see discussion in.
130   pub discussion_languages: Option<Vec<LanguageId>>,
131   /// Generates a TOTP / 2-factor authentication token.
132   ///
133   /// None leaves it as is, true will generate or regenerate it, false clears it out.
134   pub generate_totp_2fa: Option<bool>,
135   pub auth: Sensitive<String>,
136   /// Open links in a new tab
137   pub open_links_in_new_tab: Option<bool>,
138   /// Enable infinite scroll
139   pub infinite_scroll_enabled: Option<bool>,
140 }
141
142 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
143 #[cfg_attr(feature = "full", derive(TS))]
144 #[cfg_attr(feature = "full", ts(export))]
145 /// Changes your account password.
146 pub struct ChangePassword {
147   pub new_password: Sensitive<String>,
148   pub new_password_verify: Sensitive<String>,
149   pub old_password: Sensitive<String>,
150   pub auth: Sensitive<String>,
151 }
152
153 #[skip_serializing_none]
154 #[derive(Debug, Serialize, Deserialize, Clone)]
155 #[cfg_attr(feature = "full", derive(TS))]
156 #[cfg_attr(feature = "full", ts(export))]
157 /// A response for your login.
158 pub struct LoginResponse {
159   /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
160   pub jwt: Option<Sensitive<String>>,
161   /// If registration applications are required, this will return true for a signup response.
162   pub registration_created: bool,
163   /// If email verifications are required, this will return true for a signup response.
164   pub verify_email_sent: bool,
165 }
166
167 #[skip_serializing_none]
168 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
169 #[cfg_attr(feature = "full", derive(TS))]
170 #[cfg_attr(feature = "full", ts(export))]
171 /// Gets a person's details.
172 ///
173 /// Either person_id, or username are required.
174 pub struct GetPersonDetails {
175   pub person_id: Option<PersonId>,
176   /// Example: dessalines , or dessalines@xyz.tld
177   pub username: Option<String>,
178   pub sort: Option<SortType>,
179   pub page: Option<i64>,
180   pub limit: Option<i64>,
181   pub community_id: Option<CommunityId>,
182   pub saved_only: Option<bool>,
183   pub auth: Option<Sensitive<String>>,
184 }
185
186 #[derive(Debug, Serialize, Deserialize, Clone)]
187 #[cfg_attr(feature = "full", derive(TS))]
188 #[cfg_attr(feature = "full", ts(export))]
189 /// A person's details response.
190 pub struct GetPersonDetailsResponse {
191   pub person_view: PersonView,
192   pub comments: Vec<CommentView>,
193   pub posts: Vec<PostView>,
194   pub moderates: Vec<CommunityModeratorView>,
195 }
196
197 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
198 #[cfg_attr(feature = "full", derive(TS))]
199 #[cfg_attr(feature = "full", ts(export))]
200 /// Marks all notifications as read.
201 pub struct MarkAllAsRead {
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 /// Adds an admin to a site.
209 pub struct AddAdmin {
210   pub person_id: PersonId,
211   pub added: bool,
212   pub auth: Sensitive<String>,
213 }
214
215 #[derive(Debug, Serialize, Deserialize, Clone)]
216 #[cfg_attr(feature = "full", derive(TS))]
217 #[cfg_attr(feature = "full", ts(export))]
218 /// The response of current admins.
219 pub struct AddAdminResponse {
220   pub admins: Vec<PersonView>,
221 }
222
223 #[skip_serializing_none]
224 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
225 #[cfg_attr(feature = "full", derive(TS))]
226 #[cfg_attr(feature = "full", ts(export))]
227 /// Ban a person from the site.
228 pub struct BanPerson {
229   pub person_id: PersonId,
230   pub ban: bool,
231   /// Optionally remove all their data. Useful for new troll accounts.
232   pub remove_data: Option<bool>,
233   pub reason: Option<String>,
234   pub expires: Option<i64>,
235   pub auth: Sensitive<String>,
236 }
237
238 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
239 #[cfg_attr(feature = "full", derive(TS))]
240 #[cfg_attr(feature = "full", ts(export))]
241 /// Get a list of banned persons.
242 // TODO, this should be paged, since the list can be quite long.
243 pub struct GetBannedPersons {
244   pub auth: Sensitive<String>,
245 }
246
247 #[derive(Debug, Serialize, Deserialize, Clone)]
248 #[cfg_attr(feature = "full", derive(TS))]
249 #[cfg_attr(feature = "full", ts(export))]
250 /// The list of banned persons.
251 pub struct BannedPersonsResponse {
252   pub banned: Vec<PersonView>,
253 }
254
255 #[derive(Debug, Serialize, Deserialize, Clone)]
256 #[cfg_attr(feature = "full", derive(TS))]
257 #[cfg_attr(feature = "full", ts(export))]
258 /// A response for a banned person.
259 pub struct BanPersonResponse {
260   pub person_view: PersonView,
261   pub banned: bool,
262 }
263
264 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
265 #[cfg_attr(feature = "full", derive(TS))]
266 #[cfg_attr(feature = "full", ts(export))]
267 /// Block a person.
268 pub struct BlockPerson {
269   pub person_id: PersonId,
270   pub block: bool,
271   pub auth: Sensitive<String>,
272 }
273
274 #[derive(Debug, Serialize, Deserialize, Clone)]
275 #[cfg_attr(feature = "full", derive(TS))]
276 #[cfg_attr(feature = "full", ts(export))]
277 /// The response for a person block.
278 pub struct BlockPersonResponse {
279   pub person_view: PersonView,
280   pub blocked: bool,
281 }
282
283 #[skip_serializing_none]
284 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
285 #[cfg_attr(feature = "full", derive(TS))]
286 #[cfg_attr(feature = "full", ts(export))]
287 /// Get comment replies.
288 pub struct GetReplies {
289   pub sort: Option<CommentSortType>,
290   pub page: Option<i64>,
291   pub limit: Option<i64>,
292   pub unread_only: Option<bool>,
293   pub auth: Sensitive<String>,
294 }
295
296 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
297 #[cfg_attr(feature = "full", derive(TS))]
298 #[cfg_attr(feature = "full", ts(export))]
299 /// Fetches your replies.
300 // TODO, replies and mentions below should be redone as tagged enums.
301 pub struct GetRepliesResponse {
302   pub replies: Vec<CommentReplyView>,
303 }
304
305 #[skip_serializing_none]
306 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
307 #[cfg_attr(feature = "full", derive(TS))]
308 #[cfg_attr(feature = "full", ts(export))]
309 /// Get mentions for your user.
310 pub struct GetPersonMentions {
311   pub sort: Option<CommentSortType>,
312   pub page: Option<i64>,
313   pub limit: Option<i64>,
314   pub unread_only: Option<bool>,
315   pub auth: Sensitive<String>,
316 }
317
318 #[derive(Debug, Serialize, Deserialize, Clone)]
319 #[cfg_attr(feature = "full", derive(TS))]
320 #[cfg_attr(feature = "full", ts(export))]
321 /// The response of mentions for your user.
322 pub struct GetPersonMentionsResponse {
323   pub mentions: Vec<PersonMentionView>,
324 }
325
326 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
327 #[cfg_attr(feature = "full", derive(TS))]
328 #[cfg_attr(feature = "full", ts(export))]
329 /// Mark a person mention as read.
330 pub struct MarkPersonMentionAsRead {
331   pub person_mention_id: PersonMentionId,
332   pub read: bool,
333   pub auth: Sensitive<String>,
334 }
335
336 #[derive(Debug, Serialize, Deserialize, Clone)]
337 #[cfg_attr(feature = "full", derive(TS))]
338 #[cfg_attr(feature = "full", ts(export))]
339 /// The response for a person mention action.
340 pub struct PersonMentionResponse {
341   pub person_mention_view: PersonMentionView,
342 }
343
344 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
345 #[cfg_attr(feature = "full", derive(TS))]
346 #[cfg_attr(feature = "full", ts(export))]
347 /// Mark a comment reply as read.
348 pub struct MarkCommentReplyAsRead {
349   pub comment_reply_id: CommentReplyId,
350   pub read: bool,
351   pub auth: Sensitive<String>,
352 }
353
354 #[derive(Debug, Serialize, Deserialize, Clone)]
355 #[cfg_attr(feature = "full", derive(TS))]
356 #[cfg_attr(feature = "full", ts(export))]
357 /// The response for a comment reply action.
358 pub struct CommentReplyResponse {
359   pub comment_reply_view: CommentReplyView,
360 }
361
362 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
363 #[cfg_attr(feature = "full", derive(TS))]
364 #[cfg_attr(feature = "full", ts(export))]
365 /// Delete your account.
366 pub struct DeleteAccount {
367   pub password: Sensitive<String>,
368   pub auth: Sensitive<String>,
369 }
370
371 #[derive(Debug, Serialize, Deserialize, Clone)]
372 #[cfg_attr(feature = "full", derive(TS))]
373 #[cfg_attr(feature = "full", ts(export))]
374 /// The response of deleting your account.
375 pub struct DeleteAccountResponse {}
376
377 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
378 #[cfg_attr(feature = "full", derive(TS))]
379 #[cfg_attr(feature = "full", ts(export))]
380 /// Reset your password via email.
381 pub struct PasswordReset {
382   pub email: Sensitive<String>,
383 }
384
385 #[derive(Debug, Serialize, Deserialize, Clone)]
386 #[cfg_attr(feature = "full", derive(TS))]
387 #[cfg_attr(feature = "full", ts(export))]
388 /// The response of a password reset.
389 pub struct PasswordResetResponse {}
390
391 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
392 #[cfg_attr(feature = "full", derive(TS))]
393 #[cfg_attr(feature = "full", ts(export))]
394 /// Change your password after receiving a reset request.
395 pub struct PasswordChangeAfterReset {
396   pub token: Sensitive<String>,
397   pub password: Sensitive<String>,
398   pub password_verify: Sensitive<String>,
399 }
400
401 #[skip_serializing_none]
402 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
403 #[cfg_attr(feature = "full", derive(TS))]
404 #[cfg_attr(feature = "full", ts(export))]
405 /// Get a count of the number of reports.
406 pub struct GetReportCount {
407   pub community_id: Option<CommunityId>,
408   pub auth: Sensitive<String>,
409 }
410
411 #[skip_serializing_none]
412 #[derive(Debug, Serialize, Deserialize, Clone)]
413 #[cfg_attr(feature = "full", derive(TS))]
414 #[cfg_attr(feature = "full", ts(export))]
415 /// A response for the number of reports.
416 pub struct GetReportCountResponse {
417   pub community_id: Option<CommunityId>,
418   pub comment_reports: i64,
419   pub post_reports: i64,
420   pub private_message_reports: Option<i64>,
421 }
422
423 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
424 #[cfg_attr(feature = "full", derive(TS))]
425 #[cfg_attr(feature = "full", ts(export))]
426 /// Get a count of unread notifications.
427 pub struct GetUnreadCount {
428   pub auth: Sensitive<String>,
429 }
430
431 #[derive(Debug, Serialize, Deserialize, Clone)]
432 #[cfg_attr(feature = "full", derive(TS))]
433 #[cfg_attr(feature = "full", ts(export))]
434 /// A response containing counts for your notifications.
435 pub struct GetUnreadCountResponse {
436   pub replies: i64,
437   pub mentions: i64,
438   pub private_messages: i64,
439 }
440
441 #[derive(Serialize, Deserialize, Clone, Default, Debug)]
442 #[cfg_attr(feature = "full", derive(TS))]
443 #[cfg_attr(feature = "full", ts(export))]
444 /// Verify your email.
445 pub struct VerifyEmail {
446   pub token: String,
447 }
448
449 #[derive(Debug, Serialize, Deserialize, Clone)]
450 #[cfg_attr(feature = "full", derive(TS))]
451 #[cfg_attr(feature = "full", ts(export))]
452 /// A response to verifying your email.
453 pub struct VerifyEmailResponse {}