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()),
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()
})

View File

@@ -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 {

View File

@@ -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,