use crate::{DateTimeUtc, RoomId, Seq, UserId}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; /// Per-user per-room state: read position, notification preferences, etc. /// Not membership — any user who interacts with a room gets a state row (lazy init). #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "room_user_state")] pub struct Model { #[sea_orm(primary_key)] pub room: RoomId, #[sea_orm(primary_key)] pub user: UserId, pub last_read_seq: Option, /// Do Not Disturb: if true, suppress notifications for this room pub do_not_disturb: bool, /// DND start hour (0-23, local time). None means no scheduled DND. pub dnd_start_hour: Option, /// DND end hour (0-23, local time). None means no scheduled DND. pub dnd_end_hour: Option, pub joined_at: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { #[sea_orm( belongs_to = "super::room::Entity", from = "Column::Room", to = "super::room::Column::Id" )] Room, } impl Related for Entity { fn to() -> RelationDef { Relation::Room.def() } } impl ActiveModelBehavior for ActiveModel {}