channel_buffer_collaborator.rs

 1use crate::db::{ChannelBufferCollaboratorId, ChannelId, ReplicaId, ServerId, UserId};
 2use rpc::ConnectionId;
 3use sea_orm::entity::prelude::*;
 4
 5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "channel_buffer_collaborators")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: ChannelBufferCollaboratorId,
10    pub channel_id: ChannelId,
11    pub connection_id: i32,
12    pub connection_server_id: ServerId,
13    pub connection_lost: bool,
14    pub user_id: UserId,
15    pub replica_id: ReplicaId,
16}
17
18impl Model {
19    pub fn connection(&self) -> ConnectionId {
20        ConnectionId {
21            owner_id: self.connection_server_id.0 as u32,
22            id: self.connection_id as u32,
23        }
24    }
25}
26
27#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
28pub enum Relation {
29    #[sea_orm(
30        belongs_to = "super::channel::Entity",
31        from = "Column::ChannelId",
32        to = "super::channel::Column::Id"
33    )]
34    Channel,
35}
36
37impl Related<super::channel::Entity> for Entity {
38    fn to() -> RelationDef {
39        Relation::Channel.def()
40    }
41}
42
43impl ActiveModelBehavior for ActiveModel {}