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