Don't overwrite already resolved participants, better naming of keys
This commit is contained in:
@@ -5,14 +5,14 @@ use crate::daemon::attachment_store::AttachmentStore;
|
||||
use crate::daemon::models::Attachment;
|
||||
use kordophone::model::message::AttachmentMetadata;
|
||||
use kordophone::model::outgoing_message::OutgoingMessage;
|
||||
use kordophone_db::models::participant::Participant as DbParticipant;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Participant {
|
||||
Me,
|
||||
Remote {
|
||||
id: Option<i32>,
|
||||
display_name: String,
|
||||
handle: String,
|
||||
contact_id: Option<String>,
|
||||
},
|
||||
}
|
||||
@@ -20,8 +20,7 @@ pub enum Participant {
|
||||
impl From<String> for Participant {
|
||||
fn from(display_name: String) -> Self {
|
||||
Participant::Remote {
|
||||
id: None,
|
||||
display_name,
|
||||
handle: display_name,
|
||||
contact_id: None,
|
||||
}
|
||||
}
|
||||
@@ -30,8 +29,7 @@ impl From<String> for Participant {
|
||||
impl From<&str> for Participant {
|
||||
fn from(display_name: &str) -> Self {
|
||||
Participant::Remote {
|
||||
id: None,
|
||||
display_name: display_name.to_string(),
|
||||
handle: display_name.to_string(),
|
||||
contact_id: None,
|
||||
}
|
||||
}
|
||||
@@ -41,8 +39,8 @@ impl From<kordophone_db::models::Participant> for Participant {
|
||||
fn from(participant: kordophone_db::models::Participant) -> Self {
|
||||
match participant {
|
||||
kordophone_db::models::Participant::Me => Participant::Me,
|
||||
kordophone_db::models::Participant::Remote { id, display_name, contact_id } => {
|
||||
Participant::Remote { id, display_name, contact_id }
|
||||
kordophone_db::models::Participant::Remote { handle, contact_id } => {
|
||||
Participant::Remote { handle, contact_id }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +50,7 @@ impl Participant {
|
||||
pub fn display_name(&self) -> String {
|
||||
match self {
|
||||
Participant::Me => "(Me)".to_string(),
|
||||
Participant::Remote { display_name, .. } => display_name.clone(),
|
||||
Participant::Remote { handle, .. } => handle.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,8 +108,8 @@ impl From<Message> for kordophone_db::models::Message {
|
||||
id: message.id,
|
||||
sender: match message.sender {
|
||||
Participant::Me => kordophone_db::models::Participant::Me,
|
||||
Participant::Remote { id, display_name, contact_id } => {
|
||||
kordophone_db::models::Participant::Remote { id, display_name, contact_id }
|
||||
Participant::Remote { handle, contact_id } => {
|
||||
kordophone_db::models::Participant::Remote { handle, contact_id }
|
||||
}
|
||||
},
|
||||
text: message.text,
|
||||
@@ -146,8 +144,7 @@ impl From<kordophone::model::Message> for Message {
|
||||
id: message.guid,
|
||||
sender: match message.sender {
|
||||
Some(sender) => Participant::Remote {
|
||||
id: None,
|
||||
display_name: sender,
|
||||
handle: sender,
|
||||
contact_id: None,
|
||||
},
|
||||
None => Participant::Me,
|
||||
@@ -175,3 +172,12 @@ impl From<&OutgoingMessage> for Message {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Participant> for DbParticipant {
|
||||
fn from(participant: Participant) -> Self {
|
||||
match participant {
|
||||
Participant::Me => DbParticipant::Me,
|
||||
Participant::Remote { handle, contact_id } => DbParticipant::Remote { handle, contact_id: contact_id.clone() },
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user