41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
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<Seq>,
|
|
/// 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<i16>,
|
|
/// DND end hour (0-23, local time). None means no scheduled DND.
|
|
pub dnd_end_hour: Option<i16>,
|
|
pub joined_at: Option<DateTimeUtc>,
|
|
}
|
|
|
|
#[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<super::room::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Room.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|