]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
992136647c894b694e240de9f22176001d57fca6
[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   SortType,
6 };
7 use lemmy_db_views::structs::{CommentView, PostView};
8 use lemmy_db_views_actor::structs::{
9   CommentReplyView,
10   CommunityModeratorView,
11   PersonMentionView,
12   PersonView,
13 };
14 use serde::{Deserialize, Serialize};
15
16 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
17 pub struct Login {
18   pub username_or_email: Sensitive<String>,
19   pub password: Sensitive<String>,
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 interface_language: 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 discussion_languages: Option<Vec<LanguageId>>,
73   pub auth: Sensitive<String>,
74 }
75
76 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
77 pub struct ChangePassword {
78   pub new_password: Sensitive<String>,
79   pub new_password_verify: Sensitive<String>,
80   pub old_password: Sensitive<String>,
81   pub auth: Sensitive<String>,
82 }
83
84 #[derive(Debug, Serialize, Deserialize, Clone)]
85 pub struct LoginResponse {
86   /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
87   pub jwt: Option<Sensitive<String>>,
88   pub registration_created: bool,
89   pub verify_email_sent: bool,
90 }
91
92 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
93 pub struct GetPersonDetails {
94   pub person_id: Option<PersonId>, // One of these two are required
95   /// Example: dessalines , or dessalines@xyz.tld
96   pub username: Option<String>,
97   pub sort: Option<SortType>,
98   pub page: Option<i64>,
99   pub limit: Option<i64>,
100   pub community_id: Option<CommunityId>,
101   pub saved_only: Option<bool>,
102   pub auth: Option<Sensitive<String>>,
103 }
104
105 #[derive(Debug, Serialize, Deserialize, Clone)]
106 pub struct GetPersonDetailsResponse {
107   pub person_view: PersonView,
108   pub comments: Vec<CommentView>,
109   pub posts: Vec<PostView>,
110   pub moderates: Vec<CommunityModeratorView>,
111 }
112
113 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
114 pub struct GetRepliesResponse {
115   pub replies: Vec<CommentReplyView>,
116 }
117
118 #[derive(Debug, Serialize, Deserialize, Clone)]
119 pub struct GetPersonMentionsResponse {
120   pub mentions: Vec<PersonMentionView>,
121 }
122
123 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
124 pub struct MarkAllAsRead {
125   pub auth: Sensitive<String>,
126 }
127
128 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
129 pub struct AddAdmin {
130   pub person_id: PersonId,
131   pub added: bool,
132   pub auth: Sensitive<String>,
133 }
134
135 #[derive(Debug, Serialize, Deserialize, Clone)]
136 pub struct AddAdminResponse {
137   pub admins: Vec<PersonView>,
138 }
139
140 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
141 pub struct BanPerson {
142   pub person_id: PersonId,
143   pub ban: bool,
144   pub remove_data: Option<bool>,
145   pub reason: Option<String>,
146   pub expires: Option<i64>,
147   pub auth: Sensitive<String>,
148 }
149
150 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
151 pub struct GetBannedPersons {
152   pub auth: String,
153 }
154
155 #[derive(Debug, Serialize, Deserialize, Clone)]
156 pub struct BannedPersonsResponse {
157   pub banned: Vec<PersonView>,
158 }
159
160 #[derive(Debug, Serialize, Deserialize, Clone)]
161 pub struct BanPersonResponse {
162   pub person_view: PersonView,
163   pub banned: bool,
164 }
165
166 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
167 pub struct BlockPerson {
168   pub person_id: PersonId,
169   pub block: bool,
170   pub auth: Sensitive<String>,
171 }
172
173 #[derive(Debug, Serialize, Deserialize, Clone)]
174 pub struct BlockPersonResponse {
175   pub person_view: PersonView,
176   pub blocked: bool,
177 }
178
179 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
180 pub struct GetReplies {
181   pub sort: Option<CommentSortType>,
182   pub page: Option<i64>,
183   pub limit: Option<i64>,
184   pub unread_only: Option<bool>,
185   pub auth: Sensitive<String>,
186 }
187
188 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
189 pub struct GetPersonMentions {
190   pub sort: Option<CommentSortType>,
191   pub page: Option<i64>,
192   pub limit: Option<i64>,
193   pub unread_only: Option<bool>,
194   pub auth: Sensitive<String>,
195 }
196
197 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
198 pub struct MarkPersonMentionAsRead {
199   pub person_mention_id: PersonMentionId,
200   pub read: bool,
201   pub auth: Sensitive<String>,
202 }
203
204 #[derive(Debug, Serialize, Deserialize, Clone)]
205 pub struct PersonMentionResponse {
206   pub person_mention_view: PersonMentionView,
207 }
208
209 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
210 pub struct MarkCommentReplyAsRead {
211   pub comment_reply_id: CommentReplyId,
212   pub read: bool,
213   pub auth: Sensitive<String>,
214 }
215
216 #[derive(Debug, Serialize, Deserialize, Clone)]
217 pub struct CommentReplyResponse {
218   pub comment_reply_view: CommentReplyView,
219 }
220
221 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
222 pub struct DeleteAccount {
223   pub password: Sensitive<String>,
224   pub auth: Sensitive<String>,
225 }
226
227 #[derive(Debug, Serialize, Deserialize, Clone)]
228 pub struct DeleteAccountResponse {}
229
230 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
231 pub struct PasswordReset {
232   pub email: Sensitive<String>,
233 }
234
235 #[derive(Debug, Serialize, Deserialize, Clone)]
236 pub struct PasswordResetResponse {}
237
238 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
239 pub struct PasswordChangeAfterReset {
240   pub token: Sensitive<String>,
241   pub password: Sensitive<String>,
242   pub password_verify: Sensitive<String>,
243 }
244
245 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
246 pub struct GetReportCount {
247   pub community_id: Option<CommunityId>,
248   pub auth: Sensitive<String>,
249 }
250
251 #[derive(Debug, Serialize, Deserialize, Clone)]
252 pub struct GetReportCountResponse {
253   pub community_id: Option<CommunityId>,
254   pub comment_reports: i64,
255   pub post_reports: i64,
256   pub private_message_reports: Option<i64>,
257 }
258
259 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
260 pub struct GetUnreadCount {
261   pub auth: Sensitive<String>,
262 }
263
264 #[derive(Debug, Serialize, Deserialize, Clone)]
265 pub struct GetUnreadCountResponse {
266   pub replies: i64,
267   pub mentions: i64,
268   pub private_messages: i64,
269 }
270
271 #[derive(Serialize, Deserialize, Clone, Default, Debug)]
272 pub struct VerifyEmail {
273   pub token: String,
274 }
275
276 #[derive(Debug, Serialize, Deserialize, Clone)]
277 pub struct VerifyEmailResponse {}