From 74cb4ca1cdbe222f4898e8fc58ee4162a646414c Mon Sep 17 00:00:00 2001 From: Hocuri Date: Tue, 16 Jun 2020 13:07:14 +0200 Subject: [PATCH] Check for mime_parser.has_chat_version() instead of is_dc_message != MessengerMessage::No and avoid passing is_dc_message around, this will save us output &mut argument and simplify the logic. --- src/dc_receive_imf.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 5cd4242fa..59efa7320 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -169,7 +169,6 @@ pub async fn dc_receive_imf( &mut insert_msg_id, &mut created_db_entries, &mut create_event_to_send, - &mut is_dc_message, ) .await { @@ -229,8 +228,8 @@ pub async fn dc_receive_imf( context .do_heuristics_moves(server_folder.as_ref(), insert_msg_id) .await; - if !mime_parser.mdn_reports.is_empty() && is_dc_message != MessengerMessage::No { - // This is an MDN to a dc-message. Mark as read. + if !mime_parser.mdn_reports.is_empty() && mime_parser.has_chat_version() { + // This is a Delta Chat MDN. Mark as read. job::add( context, job::Job::new( @@ -325,7 +324,6 @@ async fn add_parts( insert_msg_id: &mut MsgId, created_db_entries: &mut Vec<(ChatId, MsgId)>, create_event_to_send: &mut Option, - is_dc_message: &mut MessengerMessage, ) -> Result<()> { let mut state: MessageState; let mut chat_id_blocked = Blocked::Not; @@ -348,7 +346,7 @@ async fn add_parts( return Ok(()); } - *is_dc_message = if mime_parser.has_chat_version() { + let mut is_dc_message = if mime_parser.has_chat_version() { MessengerMessage::Yes } else if is_reply_to_messenger_message(context, mime_parser).await { MessengerMessage::Reply @@ -360,7 +358,7 @@ async fn add_parts( let show_emails = ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await).unwrap_or_default(); if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage - && *is_dc_message == MessengerMessage::No + && is_dc_message == MessengerMessage::No { // this message is a classic email not a chat-message nor a reply to one match show_emails { @@ -389,7 +387,7 @@ async fn add_parts( // handshake may mark contacts as verified and must be processed before chats are created if mime_parser.get(HeaderDef::SecureJoin).is_some() { - *is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting + is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting *chat_id = ChatId::new(0); allow_creation = true; match handle_securejoin_handshake(context, mime_parser, from_id).await { @@ -522,7 +520,7 @@ async fn add_parts( if Blocked::Not != chat_id_blocked && state == MessageState::InFresh && !incoming_origin.is_known() - && *is_dc_message == MessengerMessage::No + && is_dc_message == MessengerMessage::No && show_emails != ShowEmails::All { state = MessageState::InNoticed; @@ -537,7 +535,7 @@ async fn add_parts( // handshake may mark contacts as verified and must be processed before chats are created if mime_parser.get(HeaderDef::SecureJoin).is_some() { - *is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting + is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting *chat_id = ChatId::new(0); allow_creation = true; match observe_securejoin_on_other_device(context, mime_parser, to_id).await { @@ -576,7 +574,7 @@ async fn add_parts( } } if chat_id.is_unset() && allow_creation { - let create_blocked = if MessengerMessage::No != *is_dc_message + let create_blocked = if MessengerMessage::No != is_dc_message && !Contact::is_blocked_load(context, to_id).await { Blocked::Not @@ -661,7 +659,6 @@ async fn add_parts( let sent_timestamp = *sent_timestamp; let is_hidden = *hidden; let chat_id = *chat_id; - let is_dc_message = *is_dc_message; let is_mdn = !mime_parser.mdn_reports.is_empty(); // TODO: can this clone be avoided?