Started working on contact resolution
This commit is contained in:
46
kordophoned/src/daemon/contact_resolver/mod.rs
Normal file
46
kordophoned/src/daemon/contact_resolver/mod.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
pub mod eds;
|
||||
pub use eds::EDSContactResolverBackend;
|
||||
|
||||
pub trait ContactResolverBackend {
|
||||
type ContactID;
|
||||
|
||||
fn resolve_contact_id(&self, address: &str) -> Option<Self::ContactID>;
|
||||
fn get_contact_display_name(&self, contact_id: &Self::ContactID) -> Option<String>;
|
||||
}
|
||||
|
||||
pub type AnyContactID = String;
|
||||
|
||||
pub struct ContactResolver<T: ContactResolverBackend> {
|
||||
backend: T,
|
||||
}
|
||||
|
||||
impl<T: ContactResolverBackend> ContactResolver<T>
|
||||
where
|
||||
T::ContactID: From<AnyContactID>,
|
||||
T::ContactID: Into<AnyContactID>,
|
||||
T: Default,
|
||||
{
|
||||
pub fn new(backend: T) -> Self {
|
||||
Self { backend }
|
||||
}
|
||||
|
||||
pub fn resolve_contact_id(&self, address: &str) -> Option<AnyContactID> {
|
||||
self.backend.resolve_contact_id(address).map(|id| id.into())
|
||||
}
|
||||
|
||||
pub fn get_contact_display_name(&self, contact_id: &AnyContactID) -> Option<String> {
|
||||
let backend_contact_id: T::ContactID = T::ContactID::from((*contact_id).clone());
|
||||
self.backend.get_contact_display_name(&backend_contact_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ContactResolverBackend> Default for ContactResolver<T>
|
||||
where
|
||||
T::ContactID: From<AnyContactID>,
|
||||
T::ContactID: Into<AnyContactID>,
|
||||
T: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new(T::default())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user