91 lines
3.0 KiB
Rust
91 lines
3.0 KiB
Rust
|
use crate::telepathy;
|
||
|
|
||
|
use dbus::arg::{RefArg, Variant};
|
||
|
use dbus::tree::MethodErr;
|
||
|
use deltachat::contact::Contact;
|
||
|
use std::collections::HashMap;
|
||
|
|
||
|
use super::Connection;
|
||
|
|
||
|
impl AsRef<dyn telepathy::ConnectionInterfaceContacts + 'static> for std::rc::Rc<Connection> {
|
||
|
fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceContacts + 'static) {
|
||
|
&**self
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TODO: extract a utility module for this?
|
||
|
type VarArgs = Variant<Box<dyn RefArg + 'static>>;
|
||
|
|
||
|
impl telepathy::ConnectionInterfaceContacts for Connection {
|
||
|
fn get_contact_attributes(
|
||
|
&self,
|
||
|
handles: Vec<u32>,
|
||
|
interfaces: Vec<&str>,
|
||
|
hold: bool,
|
||
|
) -> Result<HashMap<u32, HashMap<String, VarArgs>>, MethodErr> {
|
||
|
println!(
|
||
|
"Connection<{}>::get_contact_attributes({:?}, {:?}, {})",
|
||
|
self.id, handles, interfaces, hold
|
||
|
);
|
||
|
|
||
|
let mut out = HashMap::<u32, HashMap<String, VarArgs>>::new();
|
||
|
for id in handles.iter() {
|
||
|
// FIXME: work out how to use get_all
|
||
|
let contact = match Contact::get_by_id(&self.ctx.read().unwrap(), *id) {
|
||
|
Ok(c) => c,
|
||
|
Err(_e) => continue, // Invalid IDs are silently ignored
|
||
|
};
|
||
|
|
||
|
let mut props = HashMap::<String, VarArgs>::new();
|
||
|
// This is mandatory
|
||
|
props.insert(
|
||
|
"org.freedesktop.Telepathy.Connection/contact-id".to_string(),
|
||
|
Variant(Box::new(contact.get_addr().to_string())),
|
||
|
);
|
||
|
|
||
|
// The empty string means "no avatar"
|
||
|
props.insert(
|
||
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars/token".to_string(),
|
||
|
Variant(Box::new("".to_string())),
|
||
|
);
|
||
|
|
||
|
// TODO: we need to publish DBUS services on these endpoints
|
||
|
props.insert(
|
||
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/publish".to_string(),
|
||
|
Variant(Box::new(4)),
|
||
|
);
|
||
|
|
||
|
props.insert(
|
||
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/subscribe".to_string(),
|
||
|
Variant(Box::new(4)),
|
||
|
);
|
||
|
|
||
|
out.insert(*id, props);
|
||
|
}
|
||
|
|
||
|
Ok(out)
|
||
|
}
|
||
|
|
||
|
fn get_contact_by_id(
|
||
|
&self,
|
||
|
identifier: &str,
|
||
|
interfaces: Vec<&str>,
|
||
|
) -> Result<(u32, HashMap<String, VarArgs>), MethodErr> {
|
||
|
println!(
|
||
|
"Connection<{}>::get_contact_by_id({}, {:?})",
|
||
|
self.id, identifier, interfaces
|
||
|
);
|
||
|
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||
|
}
|
||
|
|
||
|
fn contact_attribute_interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||
|
println!("Connection<{}>::contact_attribute_interfaces()", self.id);
|
||
|
|
||
|
Ok(vec![
|
||
|
"org.freedesktop.Telepathy.Connection".to_string(),
|
||
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
||
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
||
|
])
|
||
|
}
|
||
|
}
|