contact.rs

 1use super::{ContactId, UserId};
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "contacts")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: ContactId,
 9    pub user_id_a: UserId,
10    pub user_id_b: UserId,
11    pub a_to_b: bool,
12    pub should_notify: bool,
13    pub accepted: bool,
14}
15
16#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
17pub enum Relation {
18    #[sea_orm(
19        belongs_to = "super::room_participant::Entity",
20        from = "Column::UserIdA",
21        to = "super::room_participant::Column::UserId"
22    )]
23    UserARoomParticipant,
24    #[sea_orm(
25        belongs_to = "super::room_participant::Entity",
26        from = "Column::UserIdB",
27        to = "super::room_participant::Column::UserId"
28    )]
29    UserBRoomParticipant,
30}
31
32impl ActiveModelBehavior for ActiveModel {}
33
34#[derive(Clone, Debug, PartialEq, Eq)]
35pub enum Contact {
36    Accepted {
37        user_id: UserId,
38        should_notify: bool,
39        busy: bool,
40    },
41    Outgoing {
42        user_id: UserId,
43    },
44    Incoming {
45        user_id: UserId,
46        should_notify: bool,
47    },
48}
49
50impl Contact {
51    pub fn user_id(&self) -> UserId {
52        match self {
53            Contact::Accepted { user_id, .. } => *user_id,
54            Contact::Outgoing { user_id } => *user_id,
55            Contact::Incoming { user_id, .. } => *user_id,
56        }
57    }
58}