Private
Public Access
1
0

Started working on contact resolution

This commit is contained in:
2025-06-26 16:23:53 -07:00
parent 3b30cb77c8
commit bb19db17cd
14 changed files with 405 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ pub struct Record {
pub id: i32,
pub display_name: Option<String>,
pub is_me: bool,
pub contact_id: Option<String>,
}
#[derive(Insertable)]
@@ -15,19 +16,22 @@ pub struct Record {
pub struct InsertableRecord {
pub display_name: Option<String>,
pub is_me: bool,
pub contact_id: Option<String>,
}
impl From<Participant> for InsertableRecord {
fn from(participant: Participant) -> Self {
match participant {
Participant::Me => InsertableRecord {
display_name: None,
is_me: true,
},
Participant::Remote { display_name, .. } => InsertableRecord {
display_name: Some(display_name),
is_me: false,
},
Participant::Me => InsertableRecord {
display_name: None,
is_me: true,
contact_id: None,
},
Participant::Remote { display_name, contact_id, .. } => InsertableRecord {
display_name: Some(display_name),
is_me: false,
contact_id,
},
}
}
}
@@ -50,6 +54,7 @@ impl From<Record> for Participant {
Participant::Remote {
id: Some(record.id),
display_name: record.display_name.unwrap_or_default(),
contact_id: record.contact_id,
}
}
}
@@ -58,16 +63,18 @@ impl From<Record> for Participant {
impl From<Participant> for Record {
fn from(participant: Participant) -> Self {
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,
},
Participant::Me => Record {
id: 0, // This will be set by the database
display_name: None,
is_me: true,
contact_id: None,
},
Participant::Remote { display_name, contact_id, .. } => Record {
id: 0, // This will be set by the database
display_name: Some(display_name),
is_me: false,
contact_id,
},
}
}
}

View File

@@ -29,6 +29,7 @@ impl From<kordophone::model::Message> for Message {
Some(sender) => Participant::Remote {
id: None,
display_name: sender,
contact_id: None,
},
None => Participant::Me,
},

View File

@@ -4,6 +4,7 @@ pub enum Participant {
Remote {
id: Option<i32>,
display_name: String,
contact_id: Option<String>,
},
}
@@ -12,6 +13,7 @@ impl From<String> for Participant {
Participant::Remote {
id: None,
display_name,
contact_id: None,
}
}
}
@@ -21,6 +23,7 @@ impl From<&str> for Participant {
Participant::Remote {
id: None,
display_name: display_name.to_string(),
contact_id: None,
}
}
}

View File

@@ -13,8 +13,7 @@ use crate::{
},
Conversation, Message, Participant,
},
schema,
target,
schema, target,
};
pub struct Repository<'a> {
@@ -195,6 +194,7 @@ impl<'a> Repository<'a> {
let new_participant = InsertableParticipantRecord {
display_name: Some(display_name.clone()),
is_me: false,
contact_id: None,
};
diesel::insert_into(participants_dsl::participants)
@@ -371,11 +371,27 @@ impl<'a> Repository<'a> {
)
}
/// Update the contact_id for an existing participant record.
pub fn update_participant_contact(
&mut self,
participant_db_id: i32,
new_contact_id: &str,
) -> Result<()> {
use crate::schema::participants::dsl::*;
log::debug!(target: target::REPOSITORY, "Updating participant contact id {} => {}", participant_db_id, new_contact_id);
diesel::update(participants.filter(id.eq(participant_db_id)))
.set(contact_id.eq(Some(new_contact_id.to_string())))
.execute(self.connection)?;
Ok(())
}
fn get_or_create_participant(&mut self, participant: &Participant) -> Option<i32> {
match participant {
Participant::Me => None,
Participant::Remote {
display_name: p_name,
contact_id: c_id,
..
} => {
use crate::schema::participants::dsl::*;
@@ -393,6 +409,7 @@ impl<'a> Repository<'a> {
let participant_record = InsertableParticipantRecord {
display_name: Some(participant.display_name()),
is_me: false,
contact_id: c_id.clone(),
};
diesel::insert_into(participants)

View File

@@ -16,6 +16,7 @@ diesel::table! {
id -> Integer,
display_name -> Nullable<Text>,
is_me -> Bool,
contact_id -> Nullable<Text>,
}
}