Fix ffi and clippy

This commit is contained in:
jikstra
2020-01-20 18:56:11 +01:00
parent bedfb74a09
commit 5a84ce06f2
3 changed files with 22 additions and 31 deletions

View File

@@ -721,17 +721,14 @@ pub unsafe extern "C" fn dc_get_chatlist_json(
qs.as_ref().map(|x| x.as_str()), qs.as_ref().map(|x| x.as_str()),
qi, qi,
) { ) {
Ok(list) => { Ok(list) => list.to_json(),
list.to_json() Err(_) => "".to_string(),
}
Err(_) => ptr::null_mut(),
} }
}) })
.unwrap_or_else(|_| ptr::null_mut()) .unwrap_or_else(|_| "".to_string())
.strdup()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn dc_create_chat_by_msg_id(context: *mut dc_context_t, msg_id: u32) -> u32 { pub unsafe extern "C" fn dc_create_chat_by_msg_id(context: *mut dc_context_t, msg_id: u32) -> u32 {
if context.is_null() { 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] #[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, context: *mut dc_context_t,
chat_id: u32, chat_id: u32,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
@@ -2469,24 +2466,18 @@ pub unsafe extern "C" fn dc_chat_get_info_json(
let ffi_context = &*context; let ffi_context = &*context;
ffi_context ffi_context
.with_inner(|ctx| { .with_inner(|ctx| {
let chat = match chat::Chat::load_from_db(ctx, ChatId::new(chat_id)) { let chatlist_item =
Ok(chat) => chat, match chatlist::ChatlistItem::load_from_db(ctx, ChatId::new(chat_id)) {
Err(err) => { Ok(chatlist_item) => chatlist_item,
error!(ctx, "dc_get_chat_info_json() failed to load chat: {}", err); Err(err) => {
return "".strdup(); error!(
} ctx,
}; "dc_get_chat_info_json() failed to load chatlist_item: {}", err
let info = match chat.get_info(ctx) { );
Ok(info) => info, return "".strdup();
Err(err) => { }
error!( };
ctx, serde_json::to_string(&chatlist_item)
"dc_get_chat_info_json() failed to get chat info: {}", err
);
return "".strdup();
}
};
serde_json::to_string(&info)
.unwrap_or_log_default(ctx, "dc_get_chat_info_json() failed to serialise to json") .unwrap_or_log_default(ctx, "dc_get_chat_info_json() failed to serialise to json")
.strdup() .strdup()
}) })

View File

@@ -4,8 +4,8 @@ use crate::chat::*;
use crate::constants::*; use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::*; use crate::context::*;
use crate::error::{Error, Result}; use crate::error::{Result};
use crate::lot::{Lot, Meaning}; use crate::lot::{Lot};
use crate::message::{Message, MessageState, MsgId, MessageSummary}; use crate::message::{Message, MessageState, MsgId, MessageSummary};
use crate::stock::StockMessage; use crate::stock::StockMessage;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -300,7 +300,7 @@ impl Chatlist {
}; };
let lastmsg_id = self.ids[index].1; 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 { pub fn get_summary_by_chat(context: &Context, chat: &Chat) -> MessageSummary {

View File

@@ -481,7 +481,7 @@ impl Message {
None 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 { pub fn get_summarytext(&self, context: &Context, approx_characters: usize) -> String {
@@ -773,7 +773,7 @@ impl MessageSummary {
message_summary message_summary
} }
pub fn into_lot(&mut self) -> Lot { pub fn to_lot(&self) -> Lot {
Lot { Lot {
text1: self.text1.clone(), text1: self.text1.clone(),
text1_meaning: self.text1_meaning, text1_meaning: self.text1_meaning,