X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapi_common%2Fsrc%2Fperson.rs;h=031bc6c7e88cba34f6ceb1b07cab686857ce0466;hb=9b5e765364ecf7de64c9cbc7a452ccfaabce5449;hp=7767da460d82e118f7b21c51774eb0fcf6e2aad9;hpb=4c8f2e976effe381d4ea1914462c43242a8c64fd;p=lemmy.git diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 7767da46..031bc6c7 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -1,245 +1,451 @@ -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)] +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; + +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Logging into lemmy. pub struct Login { - pub username_or_email: String, - pub password: String, + pub username_or_email: Sensitive, + pub password: Sensitive, + /// May be required, if totp is enabled for their account. + pub totp_2fa_token: Option, } -use lemmy_db_schema::{CommunityId, PersonId, PersonMentionId, PrivateMessageId}; -#[derive(Deserialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Register / Sign up to lemmy. pub struct Register { pub username: String, - pub email: Option, - pub password: String, - pub password_verify: String, + pub password: Sensitive, + pub password_verify: Sensitive, pub show_nsfw: bool, + /// email is mandatory if email verification is enabled on the server + pub email: Option>, + /// The UUID of the captcha item. pub captcha_uuid: Option, + /// Your captcha answer. pub captcha_answer: Option, + /// A form field to trick signup bots. Should be None. + pub honeypot: Option, + /// An answer is mandatory if require application is enabled on the server + pub answer: Option, } -#[derive(Deserialize)] -pub struct GetCaptcha {} +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches a Captcha item. +pub struct GetCaptcha { + pub auth: Option>, +} -#[derive(Serialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A wrapper for the captcha response. pub struct GetCaptchaResponse { - pub ok: Option, // Will be None if captchas are disabled + /// Will be None if captchas are disabled. + pub ok: Option, } -#[derive(Serialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A captcha response. pub struct CaptchaResponse { - pub png: String, // A Base64 encoded png - pub wav: Option, // A Base64 encoded wav audio + /// A Base64 encoded png + pub png: String, + /// A Base64 encoded wav audio + pub wav: String, + /// The UUID for the captcha item. pub uuid: String, } -#[derive(Deserialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Saves settings for your user. pub struct SaveUserSettings { + /// Show nsfw posts. pub show_nsfw: Option, + /// Show post and comment scores. + pub show_scores: Option, + /// Your user's theme. pub theme: Option, - pub default_sort_type: Option, - pub default_listing_type: Option, - pub lang: Option, + pub default_sort_type: Option, + pub default_listing_type: Option, + /// The language of the lemmy interface + pub interface_language: Option, + /// A URL for your avatar. pub avatar: Option, + /// A URL for your banner. pub banner: Option, - pub preferred_username: Option, - pub email: Option, + /// Your display name, which can contain strange characters, and does not need to be unique. + pub display_name: Option, + /// Your email. + pub email: Option>, + /// Your bio / info, in markdown. pub bio: Option, + /// Your matrix user id. Ex: @my_user:matrix.org pub matrix_user_id: Option, - pub new_password: Option, - pub new_password_verify: Option, - pub old_password: Option, + /// Whether to show or hide avatars. pub show_avatars: Option, + /// Sends notifications to your email. pub send_notifications_to_email: Option, - pub auth: String, + /// Whether this account is a bot account. Users can hide these accounts easily if they wish. + pub bot_account: Option, + /// Whether to show bot accounts. + pub show_bot_accounts: Option, + /// Whether to show read posts. + pub show_read_posts: Option, + /// Whether to show notifications for new posts. + // TODO notifs need to be reworked. + pub show_new_post_notifs: Option, + /// A list of languages you are able to see discussion in. + pub discussion_languages: Option>, + /// Generates a TOTP / 2-factor authentication token. + /// + /// None leaves it as is, true will generate or regenerate it, false clears it out. + pub generate_totp_2fa: Option, + pub auth: Sensitive, + /// Open links in a new tab + pub open_links_in_new_tab: Option, + /// Enable infinite scroll + pub infinite_scroll_enabled: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Changes your account password. +pub struct ChangePassword { + pub new_password: Sensitive, + pub new_password_verify: Sensitive, + pub old_password: Sensitive, + pub auth: Sensitive, } -#[derive(Serialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response for your login. 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>, + /// If registration applications are required, this will return true for a signup response. + pub registration_created: bool, + /// If email verifications are required, this will return true for a signup response. + pub verify_email_sent: bool, } -#[derive(Deserialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Gets a person's details. +/// +/// Either person_id, or username are required. pub struct GetPersonDetails { pub person_id: Option, + /// Example: dessalines , or dessalines@xyz.tld pub username: Option, - pub sort: String, + pub sort: Option, pub page: Option, pub limit: Option, pub community_id: Option, - pub saved_only: bool, - pub auth: Option, + pub saved_only: Option, + pub auth: Option>, } -#[derive(Serialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A person's details response. pub struct GetPersonDetailsResponse { - pub person_view: PersonViewSafe, - pub follows: Vec, - pub moderates: Vec, + pub person_view: PersonView, pub comments: Vec, pub posts: Vec, + pub moderates: Vec, } -#[derive(Serialize)] -pub struct GetRepliesResponse { - pub replies: Vec, -} - -#[derive(Serialize)] -pub struct GetPersonMentionsResponse { - pub mentions: Vec, -} - -#[derive(Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Marks all notifications as read. pub struct MarkAllAsRead { - pub auth: String, + pub auth: Sensitive, } -#[derive(Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Adds an admin to a site. pub struct AddAdmin { pub person_id: PersonId, pub added: bool, - pub auth: String, + pub auth: Sensitive, } -#[derive(Serialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response of current admins. pub struct AddAdminResponse { - pub admins: Vec, + pub admins: Vec, } -#[derive(Deserialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Ban a person from the site. pub struct BanPerson { pub person_id: PersonId, pub ban: bool, - pub remove_data: bool, + /// Optionally remove all their data. Useful for new troll accounts. + pub remove_data: Option, pub reason: Option, pub expires: Option, - pub auth: String, + pub auth: Sensitive, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Get a list of banned persons. +// TODO, this should be paged, since the list can be quite long. +pub struct GetBannedPersons { + pub auth: Sensitive, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The list of banned persons. +pub struct BannedPersonsResponse { + pub banned: Vec, } -#[derive(Serialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response for a banned person. pub struct BanPersonResponse { - pub person_view: PersonViewSafe, + pub person_view: PersonView, pub banned: bool, } -#[derive(Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Block a person. +pub struct BlockPerson { + pub person_id: PersonId, + pub block: bool, + pub auth: Sensitive, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response for a person block. +pub struct BlockPersonResponse { + pub person_view: PersonView, + pub blocked: bool, +} + +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Get comment replies. pub struct GetReplies { - pub sort: String, + pub sort: Option, pub page: Option, pub limit: Option, - pub unread_only: bool, - pub auth: String, + pub unread_only: Option, + pub auth: Sensitive, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches your replies. +// TODO, replies and mentions below should be redone as tagged enums. +pub struct GetRepliesResponse { + pub replies: Vec, } -#[derive(Deserialize)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Get mentions for your user. pub struct GetPersonMentions { - pub sort: String, + pub sort: Option, pub page: Option, pub limit: Option, - pub unread_only: bool, - pub auth: String, + pub unread_only: Option, + pub auth: Sensitive, } -#[derive(Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response of mentions for your user. +pub struct GetPersonMentionsResponse { + pub mentions: Vec, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Mark a person mention as read. pub struct MarkPersonMentionAsRead { pub person_mention_id: PersonMentionId, pub read: bool, - pub auth: String, + pub auth: Sensitive, } -#[derive(Serialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response for a person mention action. 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)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Mark a comment reply as read. +pub struct MarkCommentReplyAsRead { + pub comment_reply_id: CommentReplyId, + pub read: bool, + pub auth: Sensitive, } -#[derive(Deserialize)] -pub struct PasswordReset { - pub email: String, +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response for a comment reply action. +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)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Delete your account. +pub struct DeleteAccount { + pub password: Sensitive, + pub auth: Sensitive, } -#[derive(Deserialize)] -pub struct CreatePrivateMessage { - pub content: String, - pub recipient_id: PersonId, - pub auth: String, -} +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response of deleting your account. +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)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Reset your password via email. +pub struct PasswordReset { + pub email: Sensitive, } -#[derive(Deserialize)] -pub struct DeletePrivateMessage { - pub private_message_id: PrivateMessageId, - pub deleted: bool, - pub auth: String, -} +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response of a password reset. +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)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Change your password after receiving a reset request. +pub struct PasswordChangeAfterReset { + pub token: Sensitive, + pub password: Sensitive, + pub password_verify: Sensitive, } -#[derive(Deserialize)] -pub struct GetPrivateMessages { - pub unread_only: bool, - pub page: Option, - pub limit: Option, - pub auth: String, +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Get a count of the number of reports. +pub struct GetReportCount { + pub community_id: Option, + pub auth: Sensitive, } -#[derive(Serialize, Clone)] -pub struct PrivateMessagesResponse { - pub private_messages: Vec, +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response for the number of reports. +pub struct GetReportCountResponse { + pub community_id: Option, + pub comment_reports: i64, + pub post_reports: i64, + pub private_message_reports: Option, } -#[derive(Serialize, Clone)] -pub struct PrivateMessageResponse { - pub private_message_view: PrivateMessageView, +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Get a count of unread notifications. +pub struct GetUnreadCount { + pub auth: Sensitive, } -#[derive(Serialize, Deserialize, Debug)] -pub struct GetReportCount { - pub community: Option, - pub auth: String, +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response containing counts for your notifications. +pub struct GetUnreadCountResponse { + pub replies: i64, + pub mentions: i64, + pub private_messages: i64, } -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct GetReportCountResponse { - pub community: Option, - pub comment_reports: i64, - pub post_reports: i64, +#[derive(Serialize, Deserialize, Clone, Default, Debug)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Verify your email. +pub struct VerifyEmail { + pub token: String, } + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response to verifying your email. +pub struct VerifyEmailResponse {}