channel_chat_participant.rs

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