From 667eb3b3f6e56fe0d92a78db2960e80943cc3981 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 18 May 2020 01:57:22 +0100 Subject: [PATCH] By hook or by crook, amke empathy open a window --- share/telepathy/managers/padfoot.manager | 5 ++-- src/padfoot/channel.rs | 11 +++++-- src/padfoot/channel/channel.rs | 2 +- src/padfoot/channel/messages.rs | 15 ++++++++-- src/padfoot/connection.rs | 37 ++++++++++++++++++++++-- src/padfoot/var_arg.rs | 4 +++ 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/share/telepathy/managers/padfoot.manager b/share/telepathy/managers/padfoot.manager index 407c0a6..c44c195 100644 --- a/share/telepathy/managers/padfoot.manager +++ b/share/telepathy/managers/padfoot.manager @@ -15,11 +15,12 @@ AuthenticationTypes=org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection; ConnectionInterfaces=org.freedesktop.Telepathy.Connection.Interface.Avatars;org.freedesktop.Telepathy.Connection.Interface.Contacts;org.freedesktop.Telepathy.Connection.Interface.Requests;org.freedesktop.Telepathy.Connection.Interface.SimplePresence; EnglishName=Delta Chat Icon=im-delta -Interfaces= +Interfaces=org.freedesktop.Telepathy.Protocol;org.freedesktop.Telepathy.Protocol.Interface.Presence; RequestableChannelClasses=text; VCardField=email [text] +Interfaces=org.freedesktop.Telepathy.Channel.Interface.Messages; org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Text org.freedesktop.Telepathy.Channel.TargetHandleType u=1 -allowed=org.freedesktop.Telepathy.Channel.TargetHandle;org.freedesktop.Telepathy.Channel.TargetID; +allowed=org.freedesktop.Telepathy.Channel.TargetHandle;org.freedesktop.Telepathy.Channel.TargetID;org.freedesktop.Telepathy.Channel.Interface.Messages; diff --git a/src/padfoot/channel.rs b/src/padfoot/channel.rs index ca49e43..66d87e2 100644 --- a/src/padfoot/channel.rs +++ b/src/padfoot/channel.rs @@ -32,6 +32,7 @@ pub const HANDLE_TYPE_GROUP: HandleType = 4; // Deprecated #[derive(Debug)] pub struct Channel { actq: mpsc::Sender, + chat_id: dc::chat::ChatId, ctx: Arc>, path: dbus::Path<'static>, requested: bool, @@ -46,6 +47,7 @@ pub fn channel_interfaces() -> Vec { impl Channel { pub fn new( actq: mpsc::Sender, + chat_id: dc::chat::ChatId, ctx: Arc>, path: dbus::Path<'static>, requested: bool, @@ -53,6 +55,7 @@ impl Channel { ) -> Self { Channel { actq, + chat_id, ctx, path, requested, @@ -76,18 +79,22 @@ impl Channel { self.target_handle } - fn target_contact(&self) -> Option { + pub fn target_contact(&self) -> Option { let ctx = self.ctx.read().unwrap(); dc::contact::Contact::get_by_id(&ctx, self.handle()).ok() } - fn initiator_contact(&self) -> Option { + pub fn initiator_contact(&self) -> Option { let ctx = self.ctx.read().unwrap(); dc::contact::Contact::get_by_id(&ctx, self.handle()).ok() // FIXME: this will be wrong for outbound channels } + pub fn requested(&self) -> bool { + self.requested + } + pub fn build_object_path( channel: Arc, ) -> dbus::tree::ObjectPath { diff --git a/src/padfoot/channel/channel.rs b/src/padfoot/channel/channel.rs index a116d93..65f42e6 100644 --- a/src/padfoot/channel/channel.rs +++ b/src/padfoot/channel/channel.rs @@ -77,7 +77,7 @@ impl telepathy::Channel for Channel { fn requested(&self) -> Result { println!("Channel::requested()"); - Ok(true) // FIXME: channels initiated by ourselves *will* be requested + Ok(self.requested) // FIXME: channels initiated by ourselves *will* be requested } fn initiator_handle(&self) -> Result { diff --git a/src/padfoot/channel/messages.rs b/src/padfoot/channel/messages.rs index 67aa5f3..ef9534d 100644 --- a/src/padfoot/channel/messages.rs +++ b/src/padfoot/channel/messages.rs @@ -49,9 +49,20 @@ impl telepathy::ChannelInterfaceMessages for Channel { } fn pending_messages(&self) -> Result>>> { - println!("Channel::pending_messages()"); + let out = Vec::new(); + /* + let ctx = self.ctx.read().unwrap(); + for msg_id in dc::chat::get_chat_msgs(&ctx, self.chat_id, 0, None) { + if let Ok(msg) = dc::msg::Message::load_from_db(&ctx, msg_id) { + let lot = msg.get_summary(&ctx, None); - Ok(vec![]) // FIXME: check for pending messages + if lot + } + } + + println!("Channel::pending_messages()"); + */ + Ok(out) // FIXME: check for pending messages } fn delivery_reporting_support(&self) -> Result { diff --git a/src/padfoot/connection.rs b/src/padfoot/connection.rs index 528e1c6..7b2ebca 100644 --- a/src/padfoot/connection.rs +++ b/src/padfoot/connection.rs @@ -20,7 +20,7 @@ pub use self::requests::*; mod simple_presence; pub use self::simple_presence::*; -use crate::padfoot::{Channel, VarArg}; +use crate::padfoot::{var_bool, var_str, var_str_vec, var_u32, Channel, VarArg}; use crate::telepathy; use dbus::blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection}; @@ -309,7 +309,7 @@ impl Connection { while let Some(act) = queue_receiver.try_recv().ok() { match act { DbusAction::Signal(msg) => { - print!("*** Connection<{}>: Sending message...", id); + print!("*** Connection<{}>: Sending signal: {:?}...", id, msg); match c.send(msg) { Err(e) => println!("error! {:?}", e), // FIXME: handle error better? @@ -317,9 +317,11 @@ impl Connection { } } DbusAction::NewChannel(channel) => { + let requested = channel.requested(); let chan_type = channel.chan_type(); let handle_type = channel.handle_type(); let handle = channel.handle(); + let target_id = channel.target_contact().unwrap().get_addr().to_string(); let chan_path = channel.path().clone(); let rc_channel = Arc::new(channel); @@ -335,8 +337,36 @@ impl Connection { t2.lock().unwrap().insert(op); + let mut chan_props = HashMap::::new(); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.ChannelType".to_string(), + var_str(chan_type.clone()), + ); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(), + var_u32(handle_type), + ); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.TargetHandle".to_string(), + var_u32(handle), + ); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.TargetID".to_string(), + var_str(target_id), + ); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.Requested".to_string(), + var_bool(requested), + ); + chan_props.insert( + "org.freedesktop.Telepathy.Channel.Interfaces".to_string(), + var_str_vec(vec![ + "org.freedesktop.Telepathy.Channel.Interface.Messages".to_string(), + ]), + ); + let requests_sig = telepathy::ConnectionInterfaceRequestsNewChannels { - channels: vec![(chan_path.clone(), HashMap::new())], + channels: vec![(chan_path.clone(), chan_props)], }; let legacy_sig = telepathy::ConnectionNewChannel { @@ -405,6 +435,7 @@ impl Connection { let handle = contacts.first().unwrap(); let chan = Channel::new( actq.clone(), + chat_id, ctx.clone(), chan_path, false, // FIXME: this needs to handle requested channels diff --git a/src/padfoot/var_arg.rs b/src/padfoot/var_arg.rs index 05228f4..f9e1cb5 100644 --- a/src/padfoot/var_arg.rs +++ b/src/padfoot/var_arg.rs @@ -14,6 +14,10 @@ pub fn var_str_vec(item: Vec) -> VarArg { var_arg(Box::new(item)) } +pub fn var_bool(item: bool) -> VarArg { + var_arg(Box::new(item)) +} + pub fn var_u32(item: u32) -> VarArg { var_arg(Box::new(item)) }