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