1 use crate::sensitive::Sensitive;
3 newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
8 use lemmy_db_views::structs::{CommentView, PostView};
9 use lemmy_db_views_actor::structs::{
11 CommunityModeratorView,
15 use serde::{Deserialize, Serialize};
16 use serde_with::skip_serializing_none;
17 #[cfg(feature = "full")]
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.
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>,
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.
39 pub password: Sensitive<String>,
40 pub password_verify: Sensitive<String>,
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>,
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>>,
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>,
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
80 /// A Base64 encoded wav audio
82 /// The UUID for the captcha item.
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 {
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>,
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.
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>,
138 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
139 #[cfg_attr(feature = "full", derive(TS))]
140 #[cfg_attr(feature = "full", ts(export))]
141 /// Changes your account password.
142 pub struct ChangePassword {
143 pub new_password: Sensitive<String>,
144 pub new_password_verify: Sensitive<String>,
145 pub old_password: Sensitive<String>,
146 pub auth: Sensitive<String>,
149 #[skip_serializing_none]
150 #[derive(Debug, Serialize, Deserialize, Clone)]
151 #[cfg_attr(feature = "full", derive(TS))]
152 #[cfg_attr(feature = "full", ts(export))]
153 /// A response for your login.
154 pub struct LoginResponse {
155 /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
156 pub jwt: Option<Sensitive<String>>,
157 /// If registration applications are required, this will return true for a signup response.
158 pub registration_created: bool,
159 /// If email verifications are required, this will return true for a signup response.
160 pub verify_email_sent: bool,
163 #[skip_serializing_none]
164 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
165 #[cfg_attr(feature = "full", derive(TS))]
166 #[cfg_attr(feature = "full", ts(export))]
167 /// Gets a person's details.
169 /// Either person_id, or username are required.
170 pub struct GetPersonDetails {
171 pub person_id: Option<PersonId>,
172 /// Example: dessalines , or dessalines@xyz.tld
173 pub username: Option<String>,
174 pub sort: Option<SortType>,
175 pub page: Option<i64>,
176 pub limit: Option<i64>,
177 pub community_id: Option<CommunityId>,
178 pub saved_only: Option<bool>,
179 pub auth: Option<Sensitive<String>>,
182 #[derive(Debug, Serialize, Deserialize, Clone)]
183 #[cfg_attr(feature = "full", derive(TS))]
184 #[cfg_attr(feature = "full", ts(export))]
185 /// A person's details response.
186 pub struct GetPersonDetailsResponse {
187 pub person_view: PersonView,
188 pub comments: Vec<CommentView>,
189 pub posts: Vec<PostView>,
190 pub moderates: Vec<CommunityModeratorView>,
193 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
194 #[cfg_attr(feature = "full", derive(TS))]
195 #[cfg_attr(feature = "full", ts(export))]
196 /// Marks all notifications as read.
197 pub struct MarkAllAsRead {
198 pub auth: Sensitive<String>,
201 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
202 #[cfg_attr(feature = "full", derive(TS))]
203 #[cfg_attr(feature = "full", ts(export))]
204 /// Adds an admin to a site.
205 pub struct AddAdmin {
206 pub person_id: PersonId,
208 pub auth: Sensitive<String>,
211 #[derive(Debug, Serialize, Deserialize, Clone)]
212 #[cfg_attr(feature = "full", derive(TS))]
213 #[cfg_attr(feature = "full", ts(export))]
214 /// The response of current admins.
215 pub struct AddAdminResponse {
216 pub admins: Vec<PersonView>,
219 #[skip_serializing_none]
220 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
221 #[cfg_attr(feature = "full", derive(TS))]
222 #[cfg_attr(feature = "full", ts(export))]
223 /// Ban a person from the site.
224 pub struct BanPerson {
225 pub person_id: PersonId,
227 /// Optionally remove all their data. Useful for new troll accounts.
228 pub remove_data: Option<bool>,
229 pub reason: Option<String>,
230 pub expires: Option<i64>,
231 pub auth: Sensitive<String>,
234 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
235 #[cfg_attr(feature = "full", derive(TS))]
236 #[cfg_attr(feature = "full", ts(export))]
237 /// Get a list of banned persons.
238 // TODO, this should be paged, since the list can be quite long.
239 pub struct GetBannedPersons {
240 pub auth: Sensitive<String>,
243 #[derive(Debug, Serialize, Deserialize, Clone)]
244 #[cfg_attr(feature = "full", derive(TS))]
245 #[cfg_attr(feature = "full", ts(export))]
246 /// The list of banned persons.
247 pub struct BannedPersonsResponse {
248 pub banned: Vec<PersonView>,
251 #[derive(Debug, Serialize, Deserialize, Clone)]
252 #[cfg_attr(feature = "full", derive(TS))]
253 #[cfg_attr(feature = "full", ts(export))]
254 /// A response for a banned person.
255 pub struct BanPersonResponse {
256 pub person_view: PersonView,
260 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
261 #[cfg_attr(feature = "full", derive(TS))]
262 #[cfg_attr(feature = "full", ts(export))]
264 pub struct BlockPerson {
265 pub person_id: PersonId,
267 pub auth: Sensitive<String>,
270 #[derive(Debug, Serialize, Deserialize, Clone)]
271 #[cfg_attr(feature = "full", derive(TS))]
272 #[cfg_attr(feature = "full", ts(export))]
273 /// The response for a person block.
274 pub struct BlockPersonResponse {
275 pub person_view: PersonView,
279 #[skip_serializing_none]
280 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
281 #[cfg_attr(feature = "full", derive(TS))]
282 #[cfg_attr(feature = "full", ts(export))]
283 /// Get comment replies.
284 pub struct GetReplies {
285 pub sort: Option<CommentSortType>,
286 pub page: Option<i64>,
287 pub limit: Option<i64>,
288 pub unread_only: Option<bool>,
289 pub auth: Sensitive<String>,
292 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
293 #[cfg_attr(feature = "full", derive(TS))]
294 #[cfg_attr(feature = "full", ts(export))]
295 /// Fetches your replies.
296 // TODO, replies and mentions below should be redone as tagged enums.
297 pub struct GetRepliesResponse {
298 pub replies: Vec<CommentReplyView>,
301 #[skip_serializing_none]
302 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
303 #[cfg_attr(feature = "full", derive(TS))]
304 #[cfg_attr(feature = "full", ts(export))]
305 /// Get mentions for your user.
306 pub struct GetPersonMentions {
307 pub sort: Option<CommentSortType>,
308 pub page: Option<i64>,
309 pub limit: Option<i64>,
310 pub unread_only: Option<bool>,
311 pub auth: Sensitive<String>,
314 #[derive(Debug, Serialize, Deserialize, Clone)]
315 #[cfg_attr(feature = "full", derive(TS))]
316 #[cfg_attr(feature = "full", ts(export))]
317 /// The response of mentions for your user.
318 pub struct GetPersonMentionsResponse {
319 pub mentions: Vec<PersonMentionView>,
322 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
323 #[cfg_attr(feature = "full", derive(TS))]
324 #[cfg_attr(feature = "full", ts(export))]
325 /// Mark a person mention as read.
326 pub struct MarkPersonMentionAsRead {
327 pub person_mention_id: PersonMentionId,
329 pub auth: Sensitive<String>,
332 #[derive(Debug, Serialize, Deserialize, Clone)]
333 #[cfg_attr(feature = "full", derive(TS))]
334 #[cfg_attr(feature = "full", ts(export))]
335 /// The response for a person mention action.
336 pub struct PersonMentionResponse {
337 pub person_mention_view: PersonMentionView,
340 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
341 #[cfg_attr(feature = "full", derive(TS))]
342 #[cfg_attr(feature = "full", ts(export))]
343 /// Mark a comment reply as read.
344 pub struct MarkCommentReplyAsRead {
345 pub comment_reply_id: CommentReplyId,
347 pub auth: Sensitive<String>,
350 #[derive(Debug, Serialize, Deserialize, Clone)]
351 #[cfg_attr(feature = "full", derive(TS))]
352 #[cfg_attr(feature = "full", ts(export))]
353 /// The response for a comment reply action.
354 pub struct CommentReplyResponse {
355 pub comment_reply_view: CommentReplyView,
358 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
359 #[cfg_attr(feature = "full", derive(TS))]
360 #[cfg_attr(feature = "full", ts(export))]
361 /// Delete your account.
362 pub struct DeleteAccount {
363 pub password: Sensitive<String>,
364 pub auth: Sensitive<String>,
367 #[derive(Debug, Serialize, Deserialize, Clone)]
368 #[cfg_attr(feature = "full", derive(TS))]
369 #[cfg_attr(feature = "full", ts(export))]
370 /// The response of deleting your account.
371 pub struct DeleteAccountResponse {}
373 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
374 #[cfg_attr(feature = "full", derive(TS))]
375 #[cfg_attr(feature = "full", ts(export))]
376 /// Reset your password via email.
377 pub struct PasswordReset {
378 pub email: Sensitive<String>,
381 #[derive(Debug, Serialize, Deserialize, Clone)]
382 #[cfg_attr(feature = "full", derive(TS))]
383 #[cfg_attr(feature = "full", ts(export))]
384 /// The response of a password reset.
385 pub struct PasswordResetResponse {}
387 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
388 #[cfg_attr(feature = "full", derive(TS))]
389 #[cfg_attr(feature = "full", ts(export))]
390 /// Change your password after receiving a reset request.
391 pub struct PasswordChangeAfterReset {
392 pub token: Sensitive<String>,
393 pub password: Sensitive<String>,
394 pub password_verify: Sensitive<String>,
397 #[skip_serializing_none]
398 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
399 #[cfg_attr(feature = "full", derive(TS))]
400 #[cfg_attr(feature = "full", ts(export))]
401 /// Get a count of the number of reports.
402 pub struct GetReportCount {
403 pub community_id: Option<CommunityId>,
404 pub auth: Sensitive<String>,
407 #[skip_serializing_none]
408 #[derive(Debug, Serialize, Deserialize, Clone)]
409 #[cfg_attr(feature = "full", derive(TS))]
410 #[cfg_attr(feature = "full", ts(export))]
411 /// A response for the number of reports.
412 pub struct GetReportCountResponse {
413 pub community_id: Option<CommunityId>,
414 pub comment_reports: i64,
415 pub post_reports: i64,
416 pub private_message_reports: Option<i64>,
419 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
420 #[cfg_attr(feature = "full", derive(TS))]
421 #[cfg_attr(feature = "full", ts(export))]
422 /// Get a count of unread notifications.
423 pub struct GetUnreadCount {
424 pub auth: Sensitive<String>,
427 #[derive(Debug, Serialize, Deserialize, Clone)]
428 #[cfg_attr(feature = "full", derive(TS))]
429 #[cfg_attr(feature = "full", ts(export))]
430 /// A response containing counts for your notifications.
431 pub struct GetUnreadCountResponse {
434 pub private_messages: i64,
437 #[derive(Serialize, Deserialize, Clone, Default, Debug)]
438 #[cfg_attr(feature = "full", derive(TS))]
439 #[cfg_attr(feature = "full", ts(export))]
440 /// Verify your email.
441 pub struct VerifyEmail {
445 #[derive(Debug, Serialize, Deserialize, Clone)]
446 #[cfg_attr(feature = "full", derive(TS))]
447 #[cfg_attr(feature = "full", ts(export))]
448 /// A response to verifying your email.
449 pub struct VerifyEmailResponse {}