diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index de23a9f33..af037524a 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -721,17 +721,14 @@ pub unsafe extern "C" fn dc_get_chatlist_json( qs.as_ref().map(|x| x.as_str()), qi, ) { - Ok(list) => { - list.to_json() - } - Err(_) => ptr::null_mut(), + Ok(list) => list.to_json(), + Err(_) => "".to_string(), } }) - .unwrap_or_else(|_| ptr::null_mut()) + .unwrap_or_else(|_| "".to_string()) + .strdup() } - - #[no_mangle] pub unsafe extern "C" fn dc_create_chat_by_msg_id(context: *mut dc_context_t, msg_id: u32) -> u32 { if context.is_null() { @@ -2458,7 +2455,7 @@ pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> l } #[no_mangle] -pub unsafe extern "C" fn dc_chat_get_info_json( +pub unsafe extern "C" fn dc_chatlist_get_item_json( context: *mut dc_context_t, chat_id: u32, ) -> *mut libc::c_char { @@ -2469,24 +2466,18 @@ pub unsafe extern "C" fn dc_chat_get_info_json( let ffi_context = &*context; ffi_context .with_inner(|ctx| { - let chat = match chat::Chat::load_from_db(ctx, ChatId::new(chat_id)) { - Ok(chat) => chat, - Err(err) => { - error!(ctx, "dc_get_chat_info_json() failed to load chat: {}", err); - return "".strdup(); - } - }; - let info = match chat.get_info(ctx) { - Ok(info) => info, - Err(err) => { - error!( - ctx, - "dc_get_chat_info_json() failed to get chat info: {}", err - ); - return "".strdup(); - } - }; - serde_json::to_string(&info) + let chatlist_item = + match chatlist::ChatlistItem::load_from_db(ctx, ChatId::new(chat_id)) { + Ok(chatlist_item) => chatlist_item, + Err(err) => { + error!( + ctx, + "dc_get_chat_info_json() failed to load chatlist_item: {}", err + ); + return "".strdup(); + } + }; + serde_json::to_string(&chatlist_item) .unwrap_or_log_default(ctx, "dc_get_chat_info_json() failed to serialise to json") .strdup() }) diff --git a/src/chatlist.rs b/src/chatlist.rs index 69e455b0a..1a7c58bed 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -4,8 +4,8 @@ use crate::chat::*; use crate::constants::*; use crate::contact::*; use crate::context::*; -use crate::error::{Error, Result}; -use crate::lot::{Lot, Meaning}; +use crate::error::{Result}; +use crate::lot::{Lot}; use crate::message::{Message, MessageState, MsgId, MessageSummary}; use crate::stock::StockMessage; use serde::{Deserialize, Serialize}; @@ -300,7 +300,7 @@ impl Chatlist { }; let lastmsg_id = self.ids[index].1; - Chatlist::_get_summary(context, chat, lastmsg_id).into_lot() + Chatlist::_get_summary(context, chat, lastmsg_id).to_lot() } pub fn get_summary_by_chat(context: &Context, chat: &Chat) -> MessageSummary { diff --git a/src/message.rs b/src/message.rs index 788342d79..b985e9f89 100644 --- a/src/message.rs +++ b/src/message.rs @@ -481,7 +481,7 @@ impl Message { None }; - MessageSummary::new(self, chat, contact.as_ref(), context).into_lot() + MessageSummary::new(self, chat, contact.as_ref(), context).to_lot() } pub fn get_summarytext(&self, context: &Context, approx_characters: usize) -> String { @@ -773,7 +773,7 @@ impl MessageSummary { message_summary } - pub fn into_lot(&mut self) -> Lot { + pub fn to_lot(&self) -> Lot { Lot { text1: self.text1.clone(), text1_meaning: self.text1_meaning,