From c56c10bcedbcd171d4b36a809d39a65632e9c911 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 30 Oct 2019 18:57:21 +0100 Subject: [PATCH] remove unneccessary check of is_special() + cleanups --- deltachat-ffi/src/lib.rs | 4 +--- src/chatlist.rs | 18 +++++++----------- src/imex.rs | 6 +----- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 4edfa73bd..dc3019a44 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1386,8 +1386,7 @@ pub unsafe extern "C" fn dc_get_msg(context: *mut dc_context_t, msg_id: u32) -> // C-core API returns empty messages, do the same warn!( ctx, - "dc_get_msg called with special msg_id={}, returning empty msg", - msg_id + "dc_get_msg called with special msg_id={}, returning empty msg", msg_id ); message::Message::default() } else { @@ -3035,4 +3034,3 @@ fn convert_and_prune_message_ids(msg_ids: *const u32, msg_cnt: libc::c_int) -> V msg_ids } - diff --git a/src/chatlist.rs b/src/chatlist.rs index e0a32501f..e15400f1d 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -294,18 +294,14 @@ impl Chatlist { let lastmsg_id = self.ids[index].1; let mut lastcontact = None; - let lastmsg = if !lastmsg_id.is_special() { - if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) { - if lastmsg.from_id != 1 - && (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup) - { - lastcontact = Contact::load_from_db(context, lastmsg.from_id).ok(); - } - - Some(lastmsg) - } else { - None + let lastmsg = if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) { + if lastmsg.from_id != 1 + && (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup) + { + lastcontact = Contact::load_from_db(context, lastmsg.from_id).ok(); } + + Some(lastmsg) } else { None }; diff --git a/src/imex.rs b/src/imex.rs index 36631227c..72e87269d 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -231,11 +231,7 @@ pub fn create_setup_code(_context: &Context) -> String { pub fn continue_key_transfer(context: &Context, msg_id: MsgId, setup_code: &str) -> Result<()> { ensure!(!msg_id.is_special(), "wrong id"); - let msg = Message::load_from_db(context, msg_id); - if msg.is_err() { - bail!("Message is no Autocrypt Setup Message."); - } - let msg = msg.unwrap_or_default(); + let msg = Message::load_from_db(context, msg_id)?; ensure!( msg.is_setupmessage(), "Message is no Autocrypt Setup Message."