mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 21:36:29 +03:00
checkpoint 3
This commit is contained in:
@@ -11,6 +11,7 @@ use deltachat::dc_tools::*;
|
||||
use deltachat::error::Error;
|
||||
use deltachat::imex::*;
|
||||
use deltachat::job::*;
|
||||
use deltachat::export_chat::export_chat;
|
||||
use deltachat::location;
|
||||
use deltachat::lot::LotState;
|
||||
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\
|
||||
unpin <chat-id>\n\
|
||||
delchat <chat-id>\n\
|
||||
export-chat <chat-id>\n\
|
||||
===========================Message commands==\n\
|
||||
listmsgs <query>\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()?);
|
||||
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" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
||||
let id = MsgId::new(arg1.parse()?);
|
||||
|
||||
@@ -262,7 +262,7 @@ const DB_COMMANDS: [&str; 11] = [
|
||||
"housekeeping",
|
||||
];
|
||||
|
||||
const CHAT_COMMANDS: [&str; 26] = [
|
||||
const CHAT_COMMANDS: [&str; 27] = [
|
||||
"listchats",
|
||||
"listarchived",
|
||||
"chat",
|
||||
@@ -289,6 +289,7 @@ const CHAT_COMMANDS: [&str; 26] = [
|
||||
"pin",
|
||||
"unpin",
|
||||
"delchat",
|
||||
"export-chat",
|
||||
];
|
||||
const MESSAGE_COMMANDS: [&str; 8] = [
|
||||
"listmsgs",
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult {
|
||||
if let Ok(c) = contact {
|
||||
let profile_img_path: String;
|
||||
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)
|
||||
blobs.push(profile_img_path.clone());
|
||||
} 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();
|
||||
for message in messages {
|
||||
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 {
|
||||
html_messages.push(
|
||||
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 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 {
|
||||
html: format!(r#"<ul>{}</ul>"#, html_messages.join("")),
|
||||
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 = {
|
||||
if let Some(c) = author_cache.get(&message.get_from_id()) {
|
||||
c
|
||||
@@ -126,7 +129,7 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap<u32, ContactInfo>, mess
|
||||
r#"<div class="author-avatar">
|
||||
<img
|
||||
alt="{author_name}"
|
||||
src="{author_avatar_src}"
|
||||
src="blobs/{author_avatar_src}"
|
||||
/>
|
||||
</div>"#,
|
||||
author_name = author.name,
|
||||
@@ -161,11 +164,8 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap<u32, ContactInfo>, mess
|
||||
</div>
|
||||
<div class="metadata">
|
||||
{encryption}
|
||||
<span
|
||||
class="date date--{direction}"
|
||||
title="{full_time}"
|
||||
>{relative_time}</span
|
||||
><span class="spacer"></span>
|
||||
<span class="date date--{direction}" title="{full_time}">{relative_time}</span>
|
||||
<span class="spacer"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -36,7 +36,7 @@ pub mod constants;
|
||||
pub mod contact;
|
||||
pub mod context;
|
||||
mod e2ee;
|
||||
mod export_chat;
|
||||
pub mod export_chat;
|
||||
mod imap;
|
||||
pub mod imex;
|
||||
#[macro_use]
|
||||
|
||||
Reference in New Issue
Block a user