From 9bf879948447ae470b642c95d3011b8351424e42 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 19 Oct 2020 00:59:40 +0200 Subject: [PATCH] fix processing of protection-changed messages by #2001, processing of protection-enabled and protection-disabled messages is only done if verification-checks pass. unfortunately, these verification checks were only applied on already protected chats, so that enabling via a protection-enabled message was not possible. this is fixed by this pr. moreover, when inner_set_protection() fails, the error is shown in the chat. --- src/dc_receive_imf.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index c3a25ec65..959cde2bb 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -717,7 +717,13 @@ async fn add_parts( // if a chat is protected, check additional properties if !chat_id.is_special() { let chat = Chat::load_from_db(context, *chat_id).await?; - if chat.is_protected() { + let new_status = match mime_parser.is_system_message { + SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected), + SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected), + _ => None, + }; + + if chat.is_protected() || new_status.is_some() { if let Err(err) = check_verified_properties(context, mime_parser, from_id as u32, to_ids).await { @@ -726,12 +732,16 @@ async fn add_parts( mime_parser.repl_msg_by_error(s); } else { // change chat protection only when verification check passes - if let Some(new_status) = match mime_parser.is_system_message { - SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected), - SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected), - _ => None, - } { - chat_id.inner_set_protection(context, new_status).await?; + if let Some(new_status) = new_status { + if let Err(e) = chat_id.inner_set_protection(context, new_status).await { + chat::add_info_msg( + context, + *chat_id, + format!("Cannot set protection: {}", e), + ) + .await; + return Ok(()); // do not return an error as this would result in retrying the message + } set_better_msg( mime_parser, context.stock_protection_msg(new_status, from_id).await,