]> Untitled Git - lemmy.git/blobdiff - crates/api_common/src/person.rs
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / crates / api_common / src / person.rs
index fc061a35bc565e51ef4c5ed5e61a294f4a3229c6..10a0e806f7f3003df143849ab90885a0626dcc28 100644 (file)
-use lemmy_db_views::{
-  comment_view::CommentView,
-  post_view::PostView,
-  private_message_view::PrivateMessageView,
+use crate::sensitive::Sensitive;
+use lemmy_db_schema::{
+  newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
+  CommentSortType,
+  ListingType,
+  SortType,
 };
-use lemmy_db_views_actor::{
-  community_follower_view::CommunityFollowerView,
-  community_moderator_view::CommunityModeratorView,
-  person_mention_view::PersonMentionView,
-  person_view::PersonViewSafe,
+use lemmy_db_views::structs::{CommentView, PostView};
+use lemmy_db_views_actor::structs::{
+  CommentReplyView,
+  CommunityModeratorView,
+  PersonMentionView,
+  PersonView,
 };
 use serde::{Deserialize, Serialize};
 
-#[derive(Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct Login {
-  pub username_or_email: String,
-  pub password: String,
+  pub username_or_email: Sensitive<String>,
+  pub password: Sensitive<String>,
+  pub totp_2fa_token: Option<String>,
 }
-use lemmy_db_schema::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct Register {
   pub username: String,
-  pub email: Option<String>,
-  pub password: String,
-  pub password_verify: String,
+  pub password: Sensitive<String>,
+  pub password_verify: Sensitive<String>,
   pub show_nsfw: bool,
+  /// email is mandatory if email verification is enabled on the server
+  pub email: Option<Sensitive<String>>,
   pub captcha_uuid: Option<String>,
   pub captcha_answer: Option<String>,
+  pub honeypot: Option<String>,
+  /// An answer is mandatory if require application is enabled on the server
+  pub answer: Option<String>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct GetCaptcha {}
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct GetCaptchaResponse {
   pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
 }
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct CaptchaResponse {
   pub png: String, // A Base64 encoded png
   pub wav: String, // A Base64 encoded wav audio
   pub uuid: String,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct SaveUserSettings {
   pub show_nsfw: Option<bool>,
   pub show_scores: Option<bool>,
   pub theme: Option<String>,
-  pub default_sort_type: Option<i16>,
-  pub default_listing_type: Option<i16>,
-  pub lang: Option<String>,
+  pub default_sort_type: Option<SortType>,
+  pub default_listing_type: Option<ListingType>,
+  pub interface_language: Option<String>,
   pub avatar: Option<String>,
   pub banner: Option<String>,
   pub display_name: Option<String>,
-  pub email: Option<String>,
+  pub email: Option<Sensitive<String>>,
   pub bio: Option<String>,
   pub matrix_user_id: Option<String>,
   pub show_avatars: Option<bool>,
   pub send_notifications_to_email: Option<bool>,
-  pub auth: String,
+  pub bot_account: Option<bool>,
+  pub show_bot_accounts: Option<bool>,
+  pub show_read_posts: Option<bool>,
+  pub show_new_post_notifs: Option<bool>,
+  pub discussion_languages: Option<Vec<LanguageId>>,
+  /// None leaves it as is, true will generate or regenerate it, false clears it out
+  pub generate_totp_2fa: Option<bool>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct ChangePassword {
-  pub new_password: String,
-  pub new_password_verify: String,
-  pub old_password: String,
-  pub auth: String,
+  pub new_password: Sensitive<String>,
+  pub new_password_verify: Sensitive<String>,
+  pub old_password: Sensitive<String>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct LoginResponse {
-  pub jwt: String,
+  /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
+  pub jwt: Option<Sensitive<String>>,
+  pub registration_created: bool,
+  pub verify_email_sent: bool,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct GetPersonDetails {
-  pub person_id: Option<PersonId>,
+  pub person_id: Option<PersonId>, // One of these two are required
+  /// Example: dessalines , or dessalines@xyz.tld
   pub username: Option<String>,
-  pub sort: String,
+  pub sort: Option<SortType>,
   pub page: Option<i64>,
   pub limit: Option<i64>,
   pub community_id: Option<CommunityId>,
-  pub saved_only: bool,
-  pub auth: Option<String>,
+  pub saved_only: Option<bool>,
+  pub auth: Option<Sensitive<String>>,
 }
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct GetPersonDetailsResponse {
-  pub person_view: PersonViewSafe,
-  pub follows: Vec<CommunityFollowerView>,
-  pub moderates: Vec<CommunityModeratorView>,
+  pub person_view: PersonView,
   pub comments: Vec<CommentView>,
   pub posts: Vec<PostView>,
+  pub moderates: Vec<CommunityModeratorView>,
 }
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct GetRepliesResponse {
-  pub replies: Vec<CommentView>,
+  pub replies: Vec<CommentReplyView>,
 }
 
-#[derive(Serialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct GetPersonMentionsResponse {
   pub mentions: Vec<PersonMentionView>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct MarkAllAsRead {
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct AddAdmin {
   pub person_id: PersonId,
   pub added: bool,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct AddAdminResponse {
-  pub admins: Vec<PersonViewSafe>,
+  pub admins: Vec<PersonView>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct BanPerson {
   pub person_id: PersonId,
   pub ban: bool,
-  pub remove_data: bool,
+  pub remove_data: Option<bool>,
   pub reason: Option<String>,
   pub expires: Option<i64>,
+  pub auth: Sensitive<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct GetBannedPersons {
   pub auth: String,
 }
 
-#[derive(Serialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct BannedPersonsResponse {
+  pub banned: Vec<PersonView>,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct BanPersonResponse {
-  pub person_view: PersonViewSafe,
+  pub person_view: PersonView,
   pub banned: bool,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct BlockPerson {
+  pub person_id: PersonId,
+  pub block: bool,
+  pub auth: Sensitive<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct BlockPersonResponse {
+  pub person_view: PersonView,
+  pub blocked: bool,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct GetReplies {
-  pub sort: String,
+  pub sort: Option<CommentSortType>,
   pub page: Option<i64>,
   pub limit: Option<i64>,
-  pub unread_only: bool,
-  pub auth: String,
+  pub unread_only: Option<bool>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct GetPersonMentions {
-  pub sort: String,
+  pub sort: Option<CommentSortType>,
   pub page: Option<i64>,
   pub limit: Option<i64>,
-  pub unread_only: bool,
-  pub auth: String,
+  pub unread_only: Option<bool>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct MarkPersonMentionAsRead {
   pub person_mention_id: PersonMentionId,
   pub read: bool,
-  pub auth: String,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct PersonMentionResponse {
   pub person_mention_view: PersonMentionView,
 }
 
-#[derive(Deserialize)]
-pub struct DeleteAccount {
-  pub password: String,
-  pub auth: String,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct MarkCommentReplyAsRead {
+  pub comment_reply_id: CommentReplyId,
+  pub read: bool,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
-pub struct PasswordReset {
-  pub email: String,
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct CommentReplyResponse {
+  pub comment_reply_view: CommentReplyView,
 }
 
-#[derive(Serialize, Clone)]
-pub struct PasswordResetResponse {}
-
-#[derive(Deserialize)]
-pub struct PasswordChange {
-  pub token: String,
-  pub password: String,
-  pub password_verify: String,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct DeleteAccount {
+  pub password: Sensitive<String>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
-pub struct CreatePrivateMessage {
-  pub content: String,
-  pub recipient_id: PersonId,
-  pub auth: String,
-}
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct DeleteAccountResponse {}
 
-#[derive(Deserialize)]
-pub struct EditPrivateMessage {
-  pub private_message_id: PrivateMessageId,
-  pub content: String,
-  pub auth: String,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct PasswordReset {
+  pub email: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
-pub struct DeletePrivateMessage {
-  pub private_message_id: PrivateMessageId,
-  pub deleted: bool,
-  pub auth: String,
-}
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct PasswordResetResponse {}
 
-#[derive(Deserialize)]
-pub struct MarkPrivateMessageAsRead {
-  pub private_message_id: PrivateMessageId,
-  pub read: bool,
-  pub auth: String,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct PasswordChangeAfterReset {
+  pub token: Sensitive<String>,
+  pub password: Sensitive<String>,
+  pub password_verify: Sensitive<String>,
 }
 
-#[derive(Deserialize)]
-pub struct GetPrivateMessages {
-  pub unread_only: bool,
-  pub page: Option<i64>,
-  pub limit: Option<i64>,
-  pub auth: String,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct GetReportCount {
+  pub community_id: Option<CommunityId>,
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Clone)]
-pub struct PrivateMessagesResponse {
-  pub private_messages: Vec<PrivateMessageView>,
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct GetReportCountResponse {
+  pub community_id: Option<CommunityId>,
+  pub comment_reports: i64,
+  pub post_reports: i64,
+  pub private_message_reports: Option<i64>,
 }
 
-#[derive(Serialize, Clone)]
-pub struct PrivateMessageResponse {
-  pub private_message_view: PrivateMessageView,
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct GetUnreadCount {
+  pub auth: Sensitive<String>,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
-pub struct GetReportCount {
-  pub community: Option<CommunityId>,
-  pub auth: String,
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct GetUnreadCountResponse {
+  pub replies: i64,
+  pub mentions: i64,
+  pub private_messages: i64,
 }
 
-#[derive(Serialize, Deserialize, Clone, Debug)]
-pub struct GetReportCountResponse {
-  pub community: Option<CommunityId>,
-  pub comment_reports: i64,
-  pub post_reports: i64,
+#[derive(Serialize, Deserialize, Clone, Default, Debug)]
+pub struct VerifyEmail {
+  pub token: String,
 }
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct VerifyEmailResponse {}