]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
First pass at invite-only migration. (#1949)
[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, Clone)]
149 pub struct BanPersonResponse {
150   pub person_view: PersonViewSafe,
151   pub banned: bool,
152 }
153
154 #[derive(Debug, Serialize, Deserialize)]
155 pub struct BlockPerson {
156   pub person_id: PersonId,
157   pub block: bool,
158   pub auth: Sensitive<String>,
159 }
160
161 #[derive(Debug, Serialize, Deserialize, Clone)]
162 pub struct BlockPersonResponse {
163   pub person_view: PersonViewSafe,
164   pub blocked: bool,
165 }
166
167 #[derive(Debug, Serialize, Deserialize)]
168 pub struct GetReplies {
169   pub sort: Option<String>,
170   pub page: Option<i64>,
171   pub limit: Option<i64>,
172   pub unread_only: Option<bool>,
173   pub auth: Sensitive<String>,
174 }
175
176 #[derive(Debug, Serialize, Deserialize)]
177 pub struct GetPersonMentions {
178   pub sort: Option<String>,
179   pub page: Option<i64>,
180   pub limit: Option<i64>,
181   pub unread_only: Option<bool>,
182   pub auth: Sensitive<String>,
183 }
184
185 #[derive(Debug, Serialize, Deserialize)]
186 pub struct MarkPersonMentionAsRead {
187   pub person_mention_id: PersonMentionId,
188   pub read: bool,
189   pub auth: Sensitive<String>,
190 }
191
192 #[derive(Debug, Serialize, Deserialize, Clone)]
193 pub struct PersonMentionResponse {
194   pub person_mention_view: PersonMentionView,
195 }
196
197 #[derive(Debug, Serialize, Deserialize)]
198 pub struct DeleteAccount {
199   pub password: Sensitive<String>,
200   pub auth: Sensitive<String>,
201 }
202
203 #[derive(Debug, Serialize, Deserialize, Clone)]
204 pub struct DeleteAccountResponse {}
205
206 #[derive(Debug, Serialize, Deserialize)]
207 pub struct PasswordReset {
208   pub email: Sensitive<String>,
209 }
210
211 #[derive(Debug, Serialize, Deserialize, Clone)]
212 pub struct PasswordResetResponse {}
213
214 #[derive(Debug, Serialize, Deserialize)]
215 pub struct PasswordChange {
216   pub token: Sensitive<String>,
217   pub password: Sensitive<String>,
218   pub password_verify: Sensitive<String>,
219 }
220
221 #[derive(Debug, Serialize, Deserialize)]
222 pub struct CreatePrivateMessage {
223   pub content: String,
224   pub recipient_id: PersonId,
225   pub auth: Sensitive<String>,
226 }
227
228 #[derive(Debug, Serialize, Deserialize)]
229 pub struct EditPrivateMessage {
230   pub private_message_id: PrivateMessageId,
231   pub content: String,
232   pub auth: Sensitive<String>,
233 }
234
235 #[derive(Debug, Serialize, Deserialize)]
236 pub struct DeletePrivateMessage {
237   pub private_message_id: PrivateMessageId,
238   pub deleted: bool,
239   pub auth: Sensitive<String>,
240 }
241
242 #[derive(Debug, Serialize, Deserialize)]
243 pub struct MarkPrivateMessageAsRead {
244   pub private_message_id: PrivateMessageId,
245   pub read: bool,
246   pub auth: Sensitive<String>,
247 }
248
249 #[derive(Debug, Serialize, Deserialize)]
250 pub struct GetPrivateMessages {
251   pub unread_only: Option<bool>,
252   pub page: Option<i64>,
253   pub limit: Option<i64>,
254   pub auth: Sensitive<String>,
255 }
256
257 #[derive(Debug, Serialize, Deserialize, Clone)]
258 pub struct PrivateMessagesResponse {
259   pub private_messages: Vec<PrivateMessageView>,
260 }
261
262 #[derive(Debug, Serialize, Deserialize, Clone)]
263 pub struct PrivateMessageResponse {
264   pub private_message_view: PrivateMessageView,
265 }
266
267 #[derive(Debug, Serialize, Deserialize)]
268 pub struct GetReportCount {
269   pub community_id: Option<CommunityId>,
270   pub auth: Sensitive<String>,
271 }
272
273 #[derive(Debug, Serialize, Deserialize, Clone)]
274 pub struct GetReportCountResponse {
275   pub community_id: Option<CommunityId>,
276   pub comment_reports: i64,
277   pub post_reports: i64,
278 }
279
280 #[derive(Debug, Serialize, Deserialize)]
281 pub struct GetUnreadCount {
282   pub auth: Sensitive<String>,
283 }
284
285 #[derive(Debug, Serialize, Deserialize, Clone)]
286 pub struct GetUnreadCountResponse {
287   pub replies: i64,
288   pub mentions: i64,
289   pub private_messages: i64,
290 }
291
292 #[derive(Serialize, Deserialize)]
293 pub struct VerifyEmail {
294   pub token: String,
295 }
296
297 #[derive(Debug, Serialize, Deserialize, Clone)]
298 pub struct VerifyEmailResponse {}