2020-05-18 21:15:56 +01:00
|
|
|
use crate::padfoot::{convert_msg, VarArg};
|
2020-05-16 23:05:14 +01:00
|
|
|
use crate::telepathy;
|
|
|
|
|
|
|
|
use dbus::tree::MethodErr;
|
2020-05-18 19:37:35 +01:00
|
|
|
use dc::message::MessageState;
|
|
|
|
use deltachat as dc;
|
2020-05-16 23:05:14 +01:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use super::{Channel, Result};
|
|
|
|
|
2020-05-17 03:01:21 +01:00
|
|
|
impl AsRef<dyn telepathy::ChannelInterfaceMessages + 'static> for std::sync::Arc<Channel> {
|
2020-05-16 23:05:14 +01:00
|
|
|
fn as_ref(&self) -> &(dyn telepathy::ChannelInterfaceMessages + 'static) {
|
|
|
|
&**self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl telepathy::ChannelInterfaceMessages for Channel {
|
|
|
|
fn send_message(&self, message: Vec<HashMap<&str, VarArg>>, flags: u32) -> Result<String> {
|
2020-05-17 00:49:46 +01:00
|
|
|
println!("Channel::send_message({:?}, {})", message, flags);
|
|
|
|
Err(MethodErr::no_arg())
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
2020-05-17 00:49:46 +01:00
|
|
|
fn get_pending_message_content(
|
|
|
|
&self,
|
|
|
|
message_id: u32,
|
|
|
|
parts: Vec<u32>,
|
|
|
|
) -> Result<HashMap<u32, VarArg>> {
|
|
|
|
println!(
|
|
|
|
"Channel::get_pending_message_content({}, {:?})",
|
|
|
|
message_id, parts
|
|
|
|
);
|
|
|
|
Err(MethodErr::no_arg())
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn supported_content_types(&self) -> Result<Vec<String>> {
|
2020-05-17 00:49:46 +01:00
|
|
|
println!("Channel::supported_content_types()");
|
2020-05-17 22:49:41 +01:00
|
|
|
|
|
|
|
Ok(vec!["text/plain".to_string()]) // TODO: image support
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn message_types(&self) -> Result<Vec<u32>> {
|
2020-05-17 00:49:46 +01:00
|
|
|
println!("Channel::message_types()");
|
2020-05-17 22:49:41 +01:00
|
|
|
|
|
|
|
Ok(vec![0]) // Normal messages. FIXME: MDNs too
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn message_part_support_flags(&self) -> Result<u32> {
|
2020-05-17 00:49:46 +01:00
|
|
|
println!("Channel::message_part_support_flags()");
|
2020-05-17 22:49:41 +01:00
|
|
|
|
|
|
|
Ok(0) // FIXME: support multipart messages
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
2020-05-18 19:37:35 +01:00
|
|
|
// Return value is an array of array of message parts
|
2020-05-16 23:05:14 +01:00
|
|
|
fn pending_messages(&self) -> Result<Vec<Vec<HashMap<String, VarArg>>>> {
|
2020-05-18 19:37:35 +01:00
|
|
|
println!("Channel::pending_messages()");
|
|
|
|
|
|
|
|
let mut out = Vec::<Vec<HashMap<String, VarArg>>>::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::message::Message::load_from_db(&ctx, msg_id) {
|
|
|
|
println!(" A message: {:?}", msg);
|
|
|
|
match msg.get_state() {
|
2020-05-18 21:15:56 +01:00
|
|
|
MessageState::InFresh | MessageState::InNoticed => out.push(convert_msg(msg)),
|
2020-05-18 19:37:35 +01:00
|
|
|
_ => continue,
|
2020-05-18 01:57:22 +01:00
|
|
|
}
|
2020-05-18 19:37:35 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-18 01:57:22 +01:00
|
|
|
|
|
|
|
Ok(out) // FIXME: check for pending messages
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn delivery_reporting_support(&self) -> Result<u32> {
|
2020-05-17 00:49:46 +01:00
|
|
|
println!("Channel::delivery_reporting_support()");
|
2020-05-17 22:49:41 +01:00
|
|
|
|
|
|
|
Ok(0) // FIXME: MDNs
|
2020-05-16 23:05:14 +01:00
|
|
|
}
|
|
|
|
}
|