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