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

@@ -49,6 +49,12 @@ mod attachment_store;
pub use attachment_store::AttachmentStore;
pub use attachment_store::AttachmentStoreEvent;
pub mod contact_resolver;
use contact_resolver::ContactResolver;
use contact_resolver::EDSContactResolverBackend;
use kordophone_db::models::participant::Participant as DbParticipant;
#[derive(Debug, Error)]
pub enum DaemonError {
#[error("Client Not Configured")]
@@ -501,10 +507,34 @@ impl Daemon {
// Insert each conversation
let num_conversations = db_conversations.len();
let contact_resolver = ContactResolver::new(EDSContactResolverBackend::default());
for conversation in db_conversations {
// Insert or update conversation and its participants
database
.with_repository(|r| r.insert_conversation(conversation))
.with_repository(|r| r.insert_conversation(conversation.clone()))
.await?;
// Resolve any new participants via the contact resolver and store their contact_id
log::trace!(target: target::SYNC, "Resolving participants for conversation: {}", conversation.guid);
let guid = conversation.guid.clone();
if let Some(saved) = database
.with_repository(|r| r.get_conversation_by_guid(&guid))
.await?
{
for p in &saved.participants {
if let DbParticipant::Remote { id: Some(pid), display_name, contact_id: None } = p {
log::trace!(target: target::SYNC, "Resolving contact id for participant: {}", display_name);
if let Some(contact) = contact_resolver.resolve_contact_id(display_name) {
log::trace!(target: target::SYNC, "Resolved contact id for participant: {}", contact);
let _ = database
.with_repository(|r| r.update_participant_contact(*pid, &contact))
.await;
} else {
log::trace!(target: target::SYNC, "No contact id found for participant: {}", display_name);
}
}
}
}
}
// Send conversations updated signal