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