use sea_orm::entity::prelude::*; use sea_orm::{EntityTrait, QueryFilter, Select}; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema, )] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum ProfileVisibility { #[default] #[sea_orm(num_value = 0)] Public, #[sea_orm(num_value = 1)] RegisteredOnly, #[sea_orm(num_value = 2)] MembersOnly, #[sea_orm(num_value = 3)] Private, } #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema, )] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum Audience { #[default] #[sea_orm(num_value = 0)] Everyone, #[sea_orm(num_value = 1)] FollowingOnly, #[sea_orm(num_value = 2)] Nobody, } #[sea_orm::model] #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[sea_orm(table_name = "users")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub uid: i64, pub username: String, #[sea_orm(unique)] pub lower_name: String, pub display_name: String, pub avatar_url: String, pub is_active: bool, pub is_restricted: bool, pub prohibit_login: bool, pub visibility: ProfileVisibility, #[sea_orm(default_value = "false")] pub bot: bool, #[sea_orm(default_value = "false")] pub system: bool, pub last_login_at: Option, pub last_login_ip_hash: Option, pub version: i32, pub passwd_hash: Option, pub password_last_changed_at: Option, pub passwd_version: Option, pub totp_encrypted_secret: Option, #[sea_orm(default_value = "false")] pub totp_enabled: bool, pub totp_last_used_at: Option, pub totp_last_counter: Option, pub timezone: Option, pub locale: Option, pub language: Option, pub created_at: OffsetDateTime, pub updated_at: OffsetDateTime, #[sea_orm(has_many)] pub emails: HasMany, #[sea_orm(has_many, relation_enum = "User")] pub notifications: HasMany, #[sea_orm(has_one)] pub profile: HasOne, #[sea_orm(has_one)] pub preferences: HasOne, #[sea_orm( self_ref, has_many, via = "user_followers", from = "Followed", to = "Follower" )] pub followers: HasMany, #[sea_orm(self_ref, has_many, via = "user_followers", reverse)] pub following: HasMany, #[sea_orm( self_ref, has_many, via = "user_blocks", from = "Blocked", to = "Blocker" )] pub blocked_by: HasMany, #[sea_orm(self_ref, has_many, via = "user_blocks", reverse)] pub blocking: HasMany, } impl Entity { pub fn active() -> Select { Self::find().filter(COLUMN.is_active.eq(true)) } } impl ActiveModelBehavior for ActiveModel {}