diff --git a/src/export_chat.rs b/src/export_chat.rs index bab0ded14..728628aab 100644 --- a/src/export_chat.rs +++ b/src/export_chat.rs @@ -106,6 +106,7 @@ struct ChatJSON { color: String, profile_img: Option, contacts: HashMap, + referenced_external_messages:Vec, messages: Vec, locations: Vec, } @@ -126,6 +127,12 @@ struct FileReference { path: String, } +#[derive(Serialize)] +struct Qoute { + quoted_text: String, + message_id: Option, +} + #[derive(Serialize)] #[serde(tag = "type")] enum ChatItemJSON { @@ -141,6 +148,9 @@ enum ChatItemJSON { location_id: Option, is_info_message: bool, show_padlock: bool, + state: MessageState, + is_forwarded: bool, + quote: Option }, MessageError { id: u32, @@ -183,6 +193,21 @@ impl ChatItemJSON { }, is_info_message: message.is_info(), show_padlock: message.get_showpadlock(), + state: message.get_state(), + is_forwarded: message.is_forwarded(), + quote: match message.quoted_text() { + Some(text) => match message.quoted_message(&context).await { + Ok(Some(msg)) => Some(Qoute { + quoted_text: text, + message_id: Some(msg.get_id().to_u32()) + }), + Err(_) | Ok(None) => Some(Qoute { + quoted_text: text, + message_id: None + }) + } + None => None + } } } } @@ -193,6 +218,7 @@ async fn export_chat_data(context: &Context, chat_id: ChatId) -> ExportChatResul // message_ids var is used for writing message info to files let mut message_ids: Vec = Vec::new(); let mut message_json: Vec = Vec::new(); + let mut referenced_external_messages: Vec = Vec::new(); for item in get_chat_msgs(context, chat_id, DC_GCM_ADDDAYMARKER, None).await { if let Some(json_item) = match item { @@ -206,6 +232,15 @@ async fn export_chat_data(context: &Context, chat_id: ChatId) -> ExportChatResul message_ids.push(message.id); // populate contactid list chat_author_ids.push(message.from_id); + + if let Ok(Some(ex_msg)) = message.quoted_message(&context).await { + if ex_msg.get_chat_id() != chat_id { + // if external add it to the file + referenced_external_messages.push(ChatItemJSON::from_message(&ex_msg, &context).await) + // contacts don't need to be referenced, because these should only be private replies + } + } + Some(ChatItemJSON::from_message(&message, &context).await) } Err(error_message) => Some(ChatItemJSON::MessageError { @@ -288,6 +323,7 @@ async fn export_chat_data(context: &Context, chat_id: ChatId) -> ExportChatResul color: format!("{:#}", chat.get_color(&context).await), profile_img: chat_avatar, contacts: chat_authors, + referenced_external_messages, messages: message_json, locations: crate::location::get_range(&context, chat_id, 0, 0, crate::dc_tools::time()) .await,