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