From 1b79f513a3d96698ffb27e0a0acc731c3127ec7d Mon Sep 17 00:00:00 2001 From: jikstra Date: Thu, 14 Nov 2019 13:12:06 +0100 Subject: [PATCH] Implement more json key/value pairs --- src/chat.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/chat.rs b/src/chat.rs index e694354cd..69bebe10c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1904,7 +1904,67 @@ pub fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: u32) -> Resul } pub fn get_info_json(context: &Context, chat_id: u32) -> Result { - let s = format!("{{\n {:?}: {:?}\n}}", "chat_id", chat_id); + let chat = Chat::load_from_db(context, chat_id).unwrap(); + + // ToDo: + // - [x] id + // - [x] type + // - [x] name + // - [x] archived + // - [x] color + // - [x] profileImage + // - [x] subtitle + // - [x] draft, + // - [ ] deaddrop, + // - [ ] summary, + // - [ ] lastUpdated, + // - [ ] freshMessageCounter, + // - [ ] email + + let profile_image = match chat.get_profile_image(context) { + Some(path) => path.into_os_string().into_string().unwrap(), + None => "".to_string() + }; + + let draft = match get_draft(context, chat_id) { + Ok(message) => { + match message { + Some(m) => m.text.unwrap_or("".to_string()) , + None => "".to_string() + } + }, + Err(_) => "".to_string() + }; + + let s = format!("{{\ + \"id\": {:?},\ + \"type\": {:?},\ + \"name\": {:?},\ + \"archived\": {:?},\ + \"grpid\": {:?},\ + \"blocked\": {:?},\ + \"param\": {:?},\ + \"gossiped_timestamp\": {:?},\ + \"is_sending_locations\": {:?},\ + \"color\": {:?},\ + \"profile_image\": {:?},\ + \"subtitle\": {:?},\ + \"draft\": {:?}\ + }}", + chat.id, + chat.typ as u32, + chat.name, + chat.archived, + chat.grpid, + chat.blocked as u32, + chat.param.to_string(), + chat.gossiped_timestamp, + chat.is_sending_locations, + chat.get_color(context), + profile_image, + chat.get_subtitle(context), + draft); + Ok(s) }