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 for std::rc::Rc { fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceContacts + 'static) { &**self } } // TODO: extract a utility module for this? type VarArgs = Variant>; impl telepathy::ConnectionInterfaceContacts for Connection { fn get_contact_attributes( &self, handles: Vec, interfaces: Vec<&str>, hold: bool, ) -> Result>, MethodErr> { println!( "Connection<{}>::get_contact_attributes({:?}, {:?}, {})", self.id(), handles, interfaces, hold ); let mut out = HashMap::>::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::::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), 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, 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(), ]) } }