]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
Adding shortname fetching for users and communities. Fixes #1662 (#1663)
[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_follower_view::CommunityFollowerView,
8   community_moderator_view::CommunityModeratorView,
9   person_mention_view::PersonMentionView,
10   person_view::PersonViewSafe,
11 };
12 use serde::{Deserialize, Serialize};
13
14 #[derive(Deserialize, Debug)]
15 pub struct Login {
16   pub username_or_email: String,
17   pub password: String,
18 }
19 use lemmy_db_schema::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
20
21 #[derive(Deserialize)]
22 pub struct Register {
23   pub username: String,
24   pub password: String,
25   pub password_verify: String,
26   pub show_nsfw: bool,
27   pub email: Option<String>,
28   pub captcha_uuid: Option<String>,
29   pub captcha_answer: Option<String>,
30 }
31
32 #[derive(Deserialize)]
33 pub struct GetCaptcha {}
34
35 #[derive(Serialize)]
36 pub struct GetCaptchaResponse {
37   pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
38 }
39
40 #[derive(Serialize)]
41 pub struct CaptchaResponse {
42   pub png: String, // A Base64 encoded png
43   pub wav: String, // A Base64 encoded wav audio
44   pub uuid: String,
45 }
46
47 #[derive(Deserialize)]
48 pub struct SaveUserSettings {
49   pub show_nsfw: Option<bool>,
50   pub show_scores: Option<bool>,
51   pub theme: Option<String>,
52   pub default_sort_type: Option<i16>,
53   pub default_listing_type: Option<i16>,
54   pub lang: Option<String>,
55   pub avatar: Option<String>,
56   pub banner: Option<String>,
57   pub display_name: Option<String>,
58   pub email: Option<String>,
59   pub bio: Option<String>,
60   pub matrix_user_id: Option<String>,
61   pub show_avatars: Option<bool>,
62   pub send_notifications_to_email: Option<bool>,
63   pub bot_account: Option<bool>,
64   pub show_bot_accounts: Option<bool>,
65   pub show_read_posts: Option<bool>,
66   pub auth: String,
67 }
68
69 #[derive(Deserialize)]
70 pub struct ChangePassword {
71   pub new_password: String,
72   pub new_password_verify: String,
73   pub old_password: String,
74   pub auth: String,
75 }
76
77 #[derive(Serialize)]
78 pub struct LoginResponse {
79   pub jwt: String,
80 }
81
82 #[derive(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<String>,
93 }
94
95 #[derive(Serialize)]
96 pub struct GetPersonDetailsResponse {
97   pub person_view: PersonViewSafe,
98   pub follows: Vec<CommunityFollowerView>,
99   pub moderates: Vec<CommunityModeratorView>,
100   pub comments: Vec<CommentView>,
101   pub posts: Vec<PostView>,
102 }
103
104 #[derive(Serialize)]
105 pub struct GetRepliesResponse {
106   pub replies: Vec<CommentView>,
107 }
108
109 #[derive(Serialize)]
110 pub struct GetPersonMentionsResponse {
111   pub mentions: Vec<PersonMentionView>,
112 }
113
114 #[derive(Deserialize)]
115 pub struct MarkAllAsRead {
116   pub auth: String,
117 }
118
119 #[derive(Deserialize)]
120 pub struct AddAdmin {
121   pub person_id: PersonId,
122   pub added: bool,
123   pub auth: String,
124 }
125
126 #[derive(Serialize, Clone)]
127 pub struct AddAdminResponse {
128   pub admins: Vec<PersonViewSafe>,
129 }
130
131 #[derive(Deserialize)]
132 pub struct BanPerson {
133   pub person_id: PersonId,
134   pub ban: bool,
135   pub remove_data: Option<bool>,
136   pub reason: Option<String>,
137   pub expires: Option<i64>,
138   pub auth: String,
139 }
140
141 #[derive(Serialize, Clone)]
142 pub struct BanPersonResponse {
143   pub person_view: PersonViewSafe,
144   pub banned: bool,
145 }
146
147 #[derive(Deserialize)]
148 pub struct GetReplies {
149   pub sort: Option<String>,
150   pub page: Option<i64>,
151   pub limit: Option<i64>,
152   pub unread_only: Option<bool>,
153   pub auth: String,
154 }
155
156 #[derive(Deserialize)]
157 pub struct GetPersonMentions {
158   pub sort: Option<String>,
159   pub page: Option<i64>,
160   pub limit: Option<i64>,
161   pub unread_only: Option<bool>,
162   pub auth: String,
163 }
164
165 #[derive(Deserialize)]
166 pub struct MarkPersonMentionAsRead {
167   pub person_mention_id: PersonMentionId,
168   pub read: bool,
169   pub auth: String,
170 }
171
172 #[derive(Serialize, Clone)]
173 pub struct PersonMentionResponse {
174   pub person_mention_view: PersonMentionView,
175 }
176
177 #[derive(Deserialize)]
178 pub struct DeleteAccount {
179   pub password: String,
180   pub auth: String,
181 }
182
183 #[derive(Deserialize)]
184 pub struct PasswordReset {
185   pub email: String,
186 }
187
188 #[derive(Serialize, Clone)]
189 pub struct PasswordResetResponse {}
190
191 #[derive(Deserialize)]
192 pub struct PasswordChange {
193   pub token: String,
194   pub password: String,
195   pub password_verify: String,
196 }
197
198 #[derive(Deserialize)]
199 pub struct CreatePrivateMessage {
200   pub content: String,
201   pub recipient_id: PersonId,
202   pub auth: String,
203 }
204
205 #[derive(Deserialize)]
206 pub struct EditPrivateMessage {
207   pub private_message_id: PrivateMessageId,
208   pub content: String,
209   pub auth: String,
210 }
211
212 #[derive(Deserialize)]
213 pub struct DeletePrivateMessage {
214   pub private_message_id: PrivateMessageId,
215   pub deleted: bool,
216   pub auth: String,
217 }
218
219 #[derive(Deserialize)]
220 pub struct MarkPrivateMessageAsRead {
221   pub private_message_id: PrivateMessageId,
222   pub read: bool,
223   pub auth: String,
224 }
225
226 #[derive(Deserialize)]
227 pub struct GetPrivateMessages {
228   pub unread_only: Option<bool>,
229   pub page: Option<i64>,
230   pub limit: Option<i64>,
231   pub auth: String,
232 }
233
234 #[derive(Serialize, Clone)]
235 pub struct PrivateMessagesResponse {
236   pub private_messages: Vec<PrivateMessageView>,
237 }
238
239 #[derive(Serialize, Clone)]
240 pub struct PrivateMessageResponse {
241   pub private_message_view: PrivateMessageView,
242 }
243
244 #[derive(Serialize, Deserialize, Debug)]
245 pub struct GetReportCount {
246   pub community: Option<CommunityId>,
247   pub auth: String,
248 }
249
250 #[derive(Serialize, Deserialize, Clone, Debug)]
251 pub struct GetReportCountResponse {
252   pub community: Option<CommunityId>,
253   pub comment_reports: i64,
254   pub post_reports: i64,
255 }