Private
Public Access
1
0

kordophone-db: adds support for the Messages table

This commit is contained in:
2025-01-20 22:05:34 -08:00
parent a8104c379c
commit 146fac2759
11 changed files with 444 additions and 28 deletions

View File

@@ -6,19 +6,28 @@ use crate::schema::conversation_participants;
#[diesel(table_name = crate::schema::participants)]
pub struct Record {
pub id: i32,
pub display_name: String
pub display_name: Option<String>,
pub is_me: bool,
}
#[derive(Insertable)]
#[diesel(table_name = crate::schema::participants)]
pub struct InsertableRecord {
pub display_name: String
pub display_name: Option<String>,
pub is_me: bool,
}
impl From<Participant> for InsertableRecord {
fn from(participant: Participant) -> Self {
InsertableRecord {
display_name: participant.display_name
match participant {
Participant::Me => InsertableRecord {
display_name: None,
is_me: true,
},
Participant::Remote { display_name, .. } => InsertableRecord {
display_name: Some(display_name),
is_me: false,
}
}
}
}
@@ -35,17 +44,30 @@ pub struct ConversationParticipant {
impl From<Record> for Participant {
fn from(record: Record) -> Self {
Participant {
display_name: record.display_name
if record.is_me {
Participant::Me
} else {
Participant::Remote {
id: Some(record.id),
display_name: record.display_name.unwrap_or_default(),
}
}
}
}
impl From<Participant> for Record {
fn from(participant: Participant) -> Self {
Record {
id: 0, // This will be set by the database
display_name: participant.display_name,
match participant {
Participant::Me => Record {
id: 0, // This will be set by the database
display_name: None,
is_me: true,
},
Participant::Remote { display_name, .. } => Record {
id: 0, // This will be set by the database
display_name: Some(display_name),
is_me: false,
}
}
}
}