From a31c6d82c962e4ca2047ba3bf5cec2f17b090852 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sat, 28 Dec 2019 11:09:02 +0100 Subject: [PATCH] Remove get_origin_by_id --- src/contact.rs | 18 +----------------- src/dc_receive_imf.rs | 5 ++++- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/contact.rs b/src/contact.rs index 9742c5854..de5414fae 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -63,7 +63,7 @@ pub struct Contact { addr: String, /// Blocked state. Use dc_contact_is_blocked to access this field. - blocked: bool, + pub blocked: bool, /// The origin/source of the contact. pub origin: Origin, @@ -892,22 +892,6 @@ impl Contact { .unwrap_or_default() as usize } - pub fn get_origin_by_id(context: &Context, contact_id: u32, ret_blocked: &mut bool) -> Origin { - let mut ret = Origin::Unknown; - *ret_blocked = false; - - if let Ok(contact) = Contact::load_from_db(context, contact_id) { - /* we could optimize this by loading only the needed fields */ - if contact.blocked { - *ret_blocked = true; - } else { - ret = contact.origin; - } - } - - ret - } - pub fn real_exists_by_id(context: &Context, contact_id: u32) -> bool { if !context.sql.is_open() || contact_id <= DC_CONTACT_ID_LAST_SPECIAL { return false; diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 1e8751a3e..a02f0d587 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -124,7 +124,10 @@ pub fn dc_receive_imf( incoming_origin = Origin::OutgoingBcc; } else if !from_ids.is_empty() { from_id = from_ids.get_index(0).cloned().unwrap_or_default(); - incoming_origin = Contact::get_origin_by_id(context, from_id, &mut from_id_blocked) + if let Ok(contact) = Contact::load_from_db(context, from_id) { + incoming_origin = contact.origin; + from_id_blocked = contact.blocked; + } } else { warn!(context, "mail has an empty From header: {:?}", field_from); // if there is no from given, from_id stays 0 which is just fine. These messages