use sea_orm::entity::prelude::*; 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, } /// Local per-user settings only. /// /// Identity and account state (username, display name, email, password, TOTP, /// active/prohibit flags, bot/system, created_at) live **exclusively** in /// the in-process identity domain and are fetched through kenauth. This row is a local anchor /// for foreign keys plus data KenApi itself owns. #[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, /// KenApi-only moderation flag (not an OAuth account state). pub is_restricted: bool, pub visibility: ProfileVisibility, pub last_login_at: Option, pub last_login_ip_hash: Option, /// Avatar uploaded into KenApi's own object storage. Empty = fall back to /// KenOAuth's resolved avatar. pub local_avatar_url: String, pub timezone: Option, pub locale: Option, pub language: Option, /// Local settings optimistic-lock version (never the OAuth account version). pub version: i32, pub updated_at: OffsetDateTime, #[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 ActiveModelBehavior for ActiveModel {}