2020-05-21 02:30:47 +01:00
|
|
|
use crate::padfoot::{var_str, var_u32, VarArg};
|
2020-05-16 14:23:20 +01:00
|
|
|
use crate::telepathy;
|
|
|
|
|
|
|
|
use dbus::tree::MethodErr;
|
2020-05-16 20:54:05 +01:00
|
|
|
use deltachat::contact::{Contact, Origin};
|
2020-05-16 14:23:20 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl telepathy::ConnectionInterfaceContacts for Connection {
|
|
|
|
fn get_contact_attributes(
|
|
|
|
&self,
|
|
|
|
handles: Vec<u32>,
|
|
|
|
interfaces: Vec<&str>,
|
|
|
|
hold: bool,
|
2020-05-16 22:11:38 +01:00
|
|
|
) -> Result<HashMap<u32, HashMap<String, VarArg>>, MethodErr> {
|
2020-05-16 14:23:20 +01:00
|
|
|
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
|
|
|
);
|
|
|
|
|
2020-05-16 22:11:38 +01:00
|
|
|
let mut out = HashMap::<u32, HashMap<String, VarArg>>::new();
|
2020-05-16 14:23:20 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2020-05-16 22:11:38 +01:00
|
|
|
let mut props = HashMap::<String, VarArg>::new();
|
2020-05-16 14:23:20 +01:00
|
|
|
// This is mandatory
|
|
|
|
props.insert(
|
|
|
|
"org.freedesktop.Telepathy.Connection/contact-id".to_string(),
|
2020-05-16 22:11:38 +01:00
|
|
|
var_str(contact.get_addr().to_string()),
|
2020-05-16 14:23:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// The empty string means "no avatar"
|
|
|
|
props.insert(
|
|
|
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars/token".to_string(),
|
2020-05-16 22:11:38 +01:00
|
|
|
var_str("".to_string()),
|
2020-05-16 14:23:20 +01:00
|
|
|
);
|
2020-05-21 02:30:47 +01:00
|
|
|
|
|
|
|
props.insert(
|
|
|
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/publish".to_string(),
|
|
|
|
var_u32(4), // YES (faking it for now)
|
|
|
|
);
|
|
|
|
|
|
|
|
props.insert(
|
|
|
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/subscribe".to_string(),
|
|
|
|
var_u32(4), // YES (faking it for now)
|
|
|
|
);
|
|
|
|
|
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>,
|
2020-05-16 22:11:38 +01:00
|
|
|
) -> Result<(u32, HashMap<String, VarArg>), MethodErr> {
|
2020-05-16 14:23:20 +01:00
|
|
|
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
|
|
|
);
|
2020-05-16 20:54:05 +01:00
|
|
|
|
|
|
|
let id = {
|
|
|
|
let ctx = &self.ctx.read().unwrap();
|
|
|
|
Contact::lookup_id_by_addr(ctx, identifier, Origin::Unknown)
|
|
|
|
};
|
|
|
|
|
|
|
|
if id == 0 {
|
|
|
|
return Err(MethodErr::no_arg()); // FIXME: should be InvalidHandle
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut contacts = self.get_contact_attributes(vec![id], interfaces, true)?;
|
|
|
|
if let Some(contact) = contacts.remove(&id) {
|
|
|
|
Ok((id, contact))
|
|
|
|
} else {
|
|
|
|
Err(MethodErr::no_arg()) // FIXME: should be InvalidHandle
|
|
|
|
}
|
2020-05-16 14:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-21 02:30:47 +01:00
|
|
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
2020-05-16 14:23:20 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|