room_participant.rs

 1use crate::db::{ChannelRole, ProjectId, RoomId, RoomParticipantId, ServerId, UserId};
 2use rpc::ConnectionId;
 3use sea_orm::entity::prelude::*;
 4
 5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "room_participants")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: RoomParticipantId,
10    pub room_id: RoomId,
11    pub user_id: UserId,
12    pub answering_connection_id: Option<i32>,
13    pub answering_connection_server_id: Option<ServerId>,
14    pub answering_connection_lost: bool,
15    pub location_kind: Option<i32>,
16    pub location_project_id: Option<ProjectId>,
17    pub initial_project_id: Option<ProjectId>,
18    pub calling_user_id: UserId,
19    pub calling_connection_id: i32,
20    pub calling_connection_server_id: Option<ServerId>,
21    pub participant_index: Option<i32>,
22    pub role: Option<ChannelRole>,
23}
24
25impl Model {
26    pub fn answering_connection(&self) -> Option<ConnectionId> {
27        Some(ConnectionId {
28            owner_id: self.answering_connection_server_id?.0 as u32,
29            id: self.answering_connection_id? as u32,
30        })
31    }
32}
33
34#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
35pub enum Relation {
36    #[sea_orm(
37        belongs_to = "super::user::Entity",
38        from = "Column::UserId",
39        to = "super::user::Column::Id"
40    )]
41    User,
42    #[sea_orm(
43        belongs_to = "super::room::Entity",
44        from = "Column::RoomId",
45        to = "super::room::Column::Id"
46    )]
47    Room,
48}
49
50impl Related<super::user::Entity> for Entity {
51    fn to() -> RelationDef {
52        Relation::User.def()
53    }
54}
55
56impl Related<super::room::Entity> for Entity {
57    fn to() -> RelationDef {
58        Relation::Room.def()
59    }
60}
61
62impl ActiveModelBehavior for ActiveModel {}