2020-05-16 14:23:20 +01:00
|
|
|
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({:?}, {:?}, {})",
|
2020-05-16 18:44:02 +01:00
|
|
|
self.id(),
|
|
|
|
handles,
|
|
|
|
interfaces,
|
|
|
|
hold
|
2020-05-16 14:23:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
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())),
|
|
|
|
);
|
2020-05-16 20:19:04 +01:00
|
|
|
/*
|
2020-05-16 14:23:20 +01:00
|
|
|
// 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)),
|
|
|
|
);
|
2020-05-16 20:19:04 +01:00
|
|
|
*/
|
2020-05-16 14:23:20 +01:00
|
|
|
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({}, {:?})",
|
2020-05-16 18:44:02 +01:00
|
|
|
self.id(),
|
|
|
|
identifier,
|
|
|
|
interfaces
|
2020-05-16 14:23:20 +01:00
|
|
|
);
|
|
|
|
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
|
|
|
}
|
|
|
|
|
|
|
|
fn contact_attribute_interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
2020-05-16 18:44:02 +01:00
|
|
|
println!("Connection<{}>::contact_attribute_interfaces()", self.id());
|
2020-05-16 14:23:20 +01:00
|
|
|
|
|
|
|
Ok(vec![
|
|
|
|
"org.freedesktop.Telepathy.Connection".to_string(),
|
|
|
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
2020-05-16 20:19:04 +01:00
|
|
|
// "org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
2020-05-16 14:23:20 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|