From d77d04e9b1f562847878743f61a2ee8ddb54fb66 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 21 May 2020 10:49:33 +0100 Subject: [PATCH] Fix messages on remote-initiated chats --- src/padfoot/channel/messages.rs | 6 ++++-- src/padfoot/connection.rs | 21 ++++++++++++--------- src/padfoot/connection/requests.rs | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/padfoot/channel/messages.rs b/src/padfoot/channel/messages.rs index a4dafb8..76c22b0 100644 --- a/src/padfoot/channel/messages.rs +++ b/src/padfoot/channel/messages.rs @@ -108,9 +108,11 @@ impl telepathy::ChannelInterfaceMessages for Channel { for msg_id in dc::chat::get_chat_msgs(&ctx, self.chat_id, 0, None) { if let Ok(msg) = dc::message::Message::load_from_db(&ctx, msg_id) { - println!(" A message: {:?}", msg); match msg.get_state() { - MessageState::InFresh | MessageState::InNoticed => out.push(convert_msg(&msg)), + MessageState::InFresh | MessageState::InNoticed => { + println!(" A message: {:?}", msg); + out.push(convert_msg(&msg)) + } _ => continue, } } diff --git a/src/padfoot/connection.rs b/src/padfoot/connection.rs index 0af1399..0bbd02b 100644 --- a/src/padfoot/connection.rs +++ b/src/padfoot/connection.rs @@ -390,10 +390,10 @@ impl Connection { ) { // Ignore messages that are self-originated. // FIXME: special-case self-chats - if msg.get_from_id() == dc::constants::DC_CONTACT_ID_SELF { - println!("from ourselves, skipping"); - continue; - } + // if msg.get_from_id() == dc::constants::DC_CONTACT_ID_SELF { + // println!("from ourselves, skipping"); + // continue; + // } let parts = convert_msg(&msg); @@ -414,20 +414,23 @@ impl Connection { let contacts = dc::chat::get_chat_contacts(&ctx.clone().read().unwrap(), chat_id); - if contacts.len() != 1 { + if contacts.len() > 1 { println!("...{} contacts in chat, ignoring!", contacts.len()); continue; } - let handle = contacts.first().unwrap(); + // FIXME: device-specific chat isn't really a self-chat + let handle = contacts + .first() + .unwrap_or(&dc::constants::DC_CONTACT_ID_SELF); let chan = Channel::new( actq.clone(), chat_id, ctx.clone(), - *handle, // initiator + *handle, // initiator is the remote contact chan_path, - false, // FIXME: this needs to handle requested channels - dc::constants::DC_CONTACT_ID_SELF, // target is us + false, // FIXME: this needs to handle requested channels + *handle, // target is always the other party ); actq.send(DbusAction::NewChannel(chan)).unwrap(); actq.send(act).unwrap(); diff --git a/src/padfoot/connection/requests.rs b/src/padfoot/connection/requests.rs index a62acf7..94a2c69 100644 --- a/src/padfoot/connection/requests.rs +++ b/src/padfoot/connection/requests.rs @@ -101,7 +101,7 @@ impl telepathy::ConnectionInterfaceRequests for Connection { self.actq.clone(), chat_id, self.ctx.clone(), - dc::constants::DC_CONTACT_ID_SELF, // initiator is self + dc::constants::DC_CONTACT_ID_SELF, // initiator is self in this case channel_path.clone(), true, // requested target_handle,