diff --git a/src/types/entities/user.rs b/src/types/entities/user.rs index fab42e0..1c8b102 100644 --- a/src/types/entities/user.rs +++ b/src/types/entities/user.rs @@ -9,63 +9,6 @@ use crate::types::{ utils::Snowflake, //util::{email::adjust_email, entities::user_setting::UserSettings}, }; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[cfg_attr(feature = "sqlx", derive(FromRow))] -pub struct User { - pub id: Snowflake, - pub username: String, - pub discriminator: String, - pub avatar: Option, - pub accent_color: Option, - pub banner: Option, - pub theme_colors: Option>, - pub pronouns: Option, - pub phone: Option, - pub desktop: bool, - pub mobile: bool, - pub premium: bool, - pub premium_type: u8, - pub bot: bool, - pub bio: String, - pub system: bool, - pub nsfw_allowed: bool, - pub mfa_enabled: bool, - pub webauthn_enabled: bool, - #[serde(skip)] - pub totp_secret: Option, - #[serde(skip)] - pub totp_last_ticket: Option, - pub created_at: DateTime, - pub premium_since: Option>, - pub verified: bool, - pub disabled: bool, - pub deleted: bool, - pub email: Option, - pub flags: String, - pub public_flags: u16, - pub purchased_flags: u16, - pub premium_usage_flags: u16, - pub rights: String, - #[cfg(feature = "sqlx")] - pub relationship_ids: sqlx::types::Json>, - #[cfg(not(feature = "sqlx"))] - pub relationship_ids: Vec, - #[cfg(feature = "sqlx")] - pub connected_account_ids: sqlx::types::Json>, - #[cfg(not(feature = "sqlx"))] - pub connected_account_ids: Vec, - #[cfg(feature = "sqlx")] - pub data: sqlx::types::Json, - #[cfg(not(feature = "sqlx"))] - pub data: UserData, - #[cfg(feature = "sqlx")] - pub fingerprints: sqlx::types::Json>, - #[cfg(not(feature = "sqlx"))] - pub fingerprints: Vec, - // pub settings: UserSettings, - pub extended_settings: Value, -} - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "sqlx", derive(Type))] pub struct UserData { @@ -73,96 +16,33 @@ pub struct UserData { pub hash: Option, } -impl Default for User { - fn default() -> Self { - Self { - id: Snowflake::generate(), - username: String::new(), - discriminator: String::new(), - avatar: None, - accent_color: None, - banner: None, - theme_colors: None, - pronouns: None, - phone: None, - desktop: false, - mobile: false, - premium: false, - premium_type: 0, - bot: false, - bio: String::new(), - system: false, - nsfw_allowed: false, - mfa_enabled: false, - webauthn_enabled: false, - totp_secret: None, - totp_last_ticket: None, - created_at: Utc::now(), - premium_since: None, - verified: false, - disabled: false, - deleted: false, - email: None, - flags: String::from("0"), - public_flags: 0, - purchased_flags: 0, - premium_usage_flags: 0, - rights: String::new(), - relationship_ids: Default::default(), - connected_account_ids: Default::default(), - data: Default::default(), - fingerprints: Default::default(), - //settings: UserSettings::default(), - extended_settings: Value::Object(Map::new()), - } - } -} - -impl User { - pub fn validate(&mut self) -> Result<(), Error> { - /*if let Some(email) = self.email.as_ref() { - self.email = Some(adjust_email(email)?); - } - - if self.discriminator.len() < 4 { - self.discriminator = format!("{:0>4}", self.discriminator); - } - Ok(())*/ - todo!() - } - - pub async fn generate_discriminator(_username: &str) -> Result { - todo!() - } -} - impl User { pub fn to_public_user(self) -> PublicUser { PublicUser::from(self) } } -#[derive(Serialize, Deserialize, Debug, Default, Clone)] -pub struct PrivateUser { - pub id: String, +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] +pub struct User { + pub id: Snowflake, username: String, discriminator: String, avatar: Option, bot: bool, system: Option, mfa_enabled: Option, - accent_color: Option, + accent_color: Option, locale: Option, verified: Option, email: Option, flags: String, - premium_since: Option, - premium_type: i8, + premium_since: Option>, + premium_type: u8, pronouns: Option, - public_flags: Option, + public_flags: Option, banner: Option, bio: String, - theme_colors: Option>, + theme_colors: Option>, phone: Option, nsfw_allowed: bool, premium: bool, @@ -185,7 +65,7 @@ pub struct PublicUser { pub bio: String, pub premium_type: u8, pub premium_since: Option>, - pub public_flags: u16, + pub public_flags: Option, } impl From for PublicUser { diff --git a/src/types/entities/user_settings.rs b/src/types/entities/user_settings.rs index b7f4e4a..6f3ac53 100644 --- a/src/types/entities/user_settings.rs +++ b/src/types/entities/user_settings.rs @@ -24,8 +24,6 @@ pub enum UserTheme { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct UserSettings { - #[serde(skip_serializing)] - pub index: String, // Database relevance only pub afk_timeout: u16, pub allow_accessibility_detection: bool, pub animate_emoji: bool, @@ -62,7 +60,6 @@ pub struct UserSettings { impl Default for UserSettings { fn default() -> Self { Self { - index: Snowflake::generate().to_string(), afk_timeout: 3600, allow_accessibility_detection: true, animate_emoji: true,