Files
telepathy-padfoot/src/padfoot/channel/messages.rs

79 lines
2.4 KiB
Rust
Raw Normal View History

use crate::padfoot::{convert_msg, VarArg};
use crate::telepathy;
use dbus::tree::MethodErr;
2020-05-18 19:37:35 +01:00
use dc::message::MessageState;
use deltachat as dc;
use std::collections::HashMap;
use super::{Channel, Result};
impl AsRef<dyn telepathy::ChannelInterfaceMessages + 'static> for std::sync::Arc<Channel> {
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-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())
}
fn supported_content_types(&self) -> Result<Vec<String>> {
2020-05-17 00:49:46 +01:00
println!("Channel::supported_content_types()");
Ok(vec!["text/plain".to_string()]) // TODO: image support
}
fn message_types(&self) -> Result<Vec<u32>> {
2020-05-17 00:49:46 +01:00
println!("Channel::message_types()");
Ok(vec![0]) // Normal messages. FIXME: MDNs too
}
fn message_part_support_flags(&self) -> Result<u32> {
2020-05-17 00:49:46 +01:00
println!("Channel::message_part_support_flags()");
Ok(0) // FIXME: support multipart messages
}
2020-05-18 19:37:35 +01:00
// Return value is an array of array of message parts
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() {
MessageState::InFresh | MessageState::InNoticed => out.push(convert_msg(msg)),
2020-05-18 19:37:35 +01:00
_ => continue,
}
2020-05-18 19:37:35 +01:00
}
}
Ok(out) // FIXME: check for pending messages
}
fn delivery_reporting_support(&self) -> Result<u32> {
2020-05-17 00:49:46 +01:00
println!("Channel::delivery_reporting_support()");
Ok(0) // FIXME: MDNs
}
}