From 95f29f7b637f5aa898b69ce39663fecf4c9a7e93 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Thu, 24 Aug 2023 14:54:14 -0300 Subject: [PATCH] fix: receive_imf: Set protection only for Chattype::Single (#4597) Also don't set protection to ProtectionBroken if it already is. Co-authored-by: Hocuri --- src/receive_imf.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index e8f6afe67..95fbfb03a 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -728,12 +728,17 @@ async fn add_parts( } } - // The next block checks if the message was sent with verified encryption - // and sets the protection of the 1:1 chat accordingly. - if is_partial_download.is_none() + // Check if the message was sent with verified encryption and set the protection of + // the 1:1 chat accordingly. + let chat = match is_partial_download.is_none() && mime_parser.get_header(HeaderDef::SecureJoin).is_none() && !is_mdn { + true => Some(Chat::load_from_db(context, chat_id).await?) + .filter(|chat| chat.typ == Chattype::Single), + false => None, + }; + if let Some(chat) = chat { let mut new_protection = match has_verified_encryption( context, mime_parser, @@ -747,17 +752,15 @@ async fn add_parts( VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected, }; - let chat = Chat::load_from_db(context, chat_id).await?; - + if chat.protected != ProtectionStatus::Unprotected + && new_protection == ProtectionStatus::Unprotected + // `chat.protected` must be maintained regardless of the `Config::VerifiedOneOnOneChats`. + // That's why the config is checked here, and not above. + && context.get_config_bool(Config::VerifiedOneOnOneChats).await? + { + new_protection = ProtectionStatus::ProtectionBroken; + } if chat.protected != new_protection { - if new_protection == ProtectionStatus::Unprotected - && context - .get_config_bool(Config::VerifiedOneOnOneChats) - .await? - { - new_protection = ProtectionStatus::ProtectionBroken; - } - // The message itself will be sorted under the device message since the device // message is `MessageState::InNoticed`, which means that all following // messages are sorted under it.