Make text messages show on incoming
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
use crate::padfoot::VarArg;
|
use crate::padfoot::{var_i64, var_str, var_u32, VarArg};
|
||||||
use crate::telepathy;
|
use crate::telepathy;
|
||||||
|
|
||||||
use dbus::tree::MethodErr;
|
use dbus::tree::MethodErr;
|
||||||
|
use dc::message::MessageState;
|
||||||
|
use deltachat as dc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::{Channel, Result};
|
use super::{Channel, Result};
|
||||||
@@ -48,20 +50,66 @@ impl telepathy::ChannelInterfaceMessages for Channel {
|
|||||||
Ok(0) // FIXME: support multipart messages
|
Ok(0) // FIXME: support multipart messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return value is an array of array of message parts
|
||||||
fn pending_messages(&self) -> Result<Vec<Vec<HashMap<String, VarArg>>>> {
|
fn pending_messages(&self) -> Result<Vec<Vec<HashMap<String, VarArg>>>> {
|
||||||
let out = Vec::new();
|
println!("Channel::pending_messages()");
|
||||||
/*
|
|
||||||
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);
|
|
||||||
|
|
||||||
if lot
|
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 => {
|
||||||
|
let mut parts = Vec::new();
|
||||||
|
let mut props = HashMap::new();
|
||||||
|
props.insert(
|
||||||
|
"message-token".to_string(),
|
||||||
|
var_str(format!("{}", msg_id.to_u32())),
|
||||||
|
);
|
||||||
|
props.insert("message-sent".to_string(), var_i64(msg.get_timestamp()));
|
||||||
|
props.insert(
|
||||||
|
"message-received".to_string(),
|
||||||
|
var_i64(msg.get_received_timestamp()),
|
||||||
|
);
|
||||||
|
props.insert("message-sender".to_string(), var_u32(msg.get_from_id()));
|
||||||
|
// props.insert("message-sender-id", var_str()); // This doesn't need to be sent
|
||||||
|
// props.insert("sender-nickname", var_str()); // Can we get away without this one?
|
||||||
|
props.insert("message-type".to_string(), var_u32(0)); // normal
|
||||||
|
|
||||||
|
// These relate to superseded messages
|
||||||
|
// props.insert("supersedes", var_str());
|
||||||
|
// props.insert("original-message-sent", var_i64());
|
||||||
|
// props.insert("original-message-received", var_i64());
|
||||||
|
|
||||||
|
props.insert("pending-message-id".to_string(), var_u32(msg_id.to_u32()));
|
||||||
|
|
||||||
|
parts.push(props);
|
||||||
|
|
||||||
|
// Don't need these
|
||||||
|
// props.insert("interface", var_str());
|
||||||
|
// props.insert("scrollback", var_vool());
|
||||||
|
// props.insert("silent", var_bool());
|
||||||
|
// props.insert("rescued", var_bool());
|
||||||
|
|
||||||
|
if let Some(text) = msg.get_text() {
|
||||||
|
let mut part = HashMap::new();
|
||||||
|
part.insert(
|
||||||
|
"content-type".to_string(),
|
||||||
|
var_str("text/plain".to_string()),
|
||||||
|
);
|
||||||
|
part.insert("content".to_string(), var_str(text));
|
||||||
|
parts.push(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.push(parts);
|
||||||
}
|
}
|
||||||
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Channel::pending_messages()");
|
|
||||||
*/
|
|
||||||
Ok(out) // FIXME: check for pending messages
|
Ok(out) // FIXME: check for pending messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,3 +21,7 @@ pub fn var_bool(item: bool) -> VarArg {
|
|||||||
pub fn var_u32(item: u32) -> VarArg {
|
pub fn var_u32(item: u32) -> VarArg {
|
||||||
var_arg(Box::new(item))
|
var_arg(Box::new(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn var_i64(item: i64) -> VarArg {
|
||||||
|
var_arg(Box::new(item))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user