checkpoint 3

This commit is contained in:
Simon Laux
2020-03-10 02:44:29 +01:00
committed by Simon
parent 817050260f
commit 9f24d57835
4 changed files with 22 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ use deltachat::dc_tools::*;
use deltachat::error::Error; use deltachat::error::Error;
use deltachat::imex::*; use deltachat::imex::*;
use deltachat::job::*; use deltachat::job::*;
use deltachat::export_chat::export_chat;
use deltachat::location; use deltachat::location;
use deltachat::lot::LotState; use deltachat::lot::LotState;
use deltachat::message::{self, Message, MessageState, MsgId}; use deltachat::message::{self, Message, MessageState, MsgId};
@@ -374,6 +375,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
pin <chat-id>\n\ pin <chat-id>\n\
unpin <chat-id>\n\ unpin <chat-id>\n\
delchat <chat-id>\n\ delchat <chat-id>\n\
export-chat <chat-id>\n\
===========================Message commands==\n\ ===========================Message commands==\n\
listmsgs <query>\n\ listmsgs <query>\n\
msginfo <msg-id>\n\ msginfo <msg-id>\n\
@@ -868,6 +870,12 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
let chat_id = ChatId::new(arg1.parse()?); let chat_id = ChatId::new(arg1.parse()?);
chat_id.delete(context)?; chat_id.delete(context)?;
} }
"export-chat" => {
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
let chat_id = ChatId::new(arg1.parse()?);
let res = export_chat(context, chat_id);
println!("{:?}", res);
}
"msginfo" => { "msginfo" => {
ensure!(!arg1.is_empty(), "Argument <msg-id> missing."); ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
let id = MsgId::new(arg1.parse()?); let id = MsgId::new(arg1.parse()?);

View File

@@ -262,7 +262,7 @@ const DB_COMMANDS: [&str; 11] = [
"housekeeping", "housekeeping",
]; ];
const CHAT_COMMANDS: [&str; 26] = [ const CHAT_COMMANDS: [&str; 27] = [
"listchats", "listchats",
"listarchived", "listarchived",
"chat", "chat",
@@ -289,6 +289,7 @@ const CHAT_COMMANDS: [&str; 26] = [
"pin", "pin",
"unpin", "unpin",
"delchat", "delchat",
"export-chat",
]; ];
const MESSAGE_COMMANDS: [&str; 8] = [ const MESSAGE_COMMANDS: [&str; 8] = [
"listmsgs", "listmsgs",

View File

@@ -57,7 +57,7 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult {
if let Ok(c) = contact { if let Ok(c) = contact {
let profile_img_path: String; let profile_img_path: String;
if let Some(path) = c.get_profile_image(context) { if let Some(path) = c.get_profile_image(context) {
profile_img_path = path.to_str().unwrap_or_else(|| "").to_owned(); profile_img_path = path.file_name().unwrap_or_else(|| std::ffi::OsStr::new("")).to_str().unwrap().to_owned();
// push referenced blobs (avatars) // push referenced blobs (avatars)
blobs.push(profile_img_path.clone()); blobs.push(profile_img_path.clone());
} else { } else {
@@ -78,10 +78,11 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult {
} }
} }
// run message_to_html for each message and generate the html that way
let mut html_messages:Vec<String> = Vec::new(); let mut html_messages:Vec<String> = Vec::new();
for message in messages { for message in messages {
if let Ok(msg) = message { if let Ok(msg) = message {
html_messages.push(message_to_html(&context, &chat_authors, msg)); html_messages.push(message_to_html(&chat_authors, msg));
} else { } else {
html_messages.push( html_messages.push(
format!( format!(
@@ -100,18 +101,20 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult {
} }
} }
// run message_to_html for each message and generate the html that way
// todo chat image, chat name and so on.. // todo chat image, chat name and so on..
// todo option to export locations as kml? // todo option to export locations as kml?
// todo export message infos and save them to txt files
// (those can be linked from the messages, they are stored in msg_info/[msg-id].txt)
ExportChatResult { ExportChatResult {
html: format!(r#"<ul>{}</ul>"#, html_messages.join("")), html: format!(r#"<ul>{}</ul>"#, html_messages.join("")),
referenced_blobs: blobs, referenced_blobs: blobs,
} }
} }
fn message_to_html(ctx: &Context, author_cache: &HashMap<u32, ContactInfo>, message: Message) -> String { fn message_to_html(author_cache: &HashMap<u32, ContactInfo>, message: Message) -> String {
let author: &ContactInfo = { let author: &ContactInfo = {
if let Some(c) = author_cache.get(&message.get_from_id()) { if let Some(c) = author_cache.get(&message.get_from_id()) {
c c
@@ -126,7 +129,7 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap<u32, ContactInfo>, mess
r#"<div class="author-avatar"> r#"<div class="author-avatar">
<img <img
alt="{author_name}" alt="{author_name}"
src="{author_avatar_src}" src="blobs/{author_avatar_src}"
/> />
</div>"#, </div>"#,
author_name = author.name, author_name = author.name,
@@ -161,11 +164,8 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap<u32, ContactInfo>, mess
</div> </div>
<div class="metadata"> <div class="metadata">
{encryption} {encryption}
<span <span class="date date--{direction}" title="{full_time}">{relative_time}</span>
class="date date--{direction}" <span class="spacer"></span>
title="{full_time}"
>{relative_time}</span
><span class="spacer"></span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -36,7 +36,7 @@ pub mod constants;
pub mod contact; pub mod contact;
pub mod context; pub mod context;
mod e2ee; mod e2ee;
mod export_chat; pub mod export_chat;
mod imap; mod imap;
pub mod imex; pub mod imex;
#[macro_use] #[macro_use]