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