refactor: move mark_recipients_as_verified() call out of has_verified_encryption()

This commit is contained in:
link2xt
2025-03-21 12:53:10 +00:00
committed by l
parent ee68b9c7ba
commit 8a5a67d6f2

View File

@@ -405,8 +405,11 @@ pub(crate) async fn receive_imf_inner(
received_msg = None; received_msg = None;
} }
let verified_encryption = let verified_encryption = has_verified_encryption(&mime_parser, from_id)?;
has_verified_encryption(context, &mime_parser, from_id, &to_ids).await?;
if verified_encryption == VerifiedEncryption::Verified {
mark_recipients_as_verified(context, from_id, &to_ids, &mime_parser).await?;
}
if verified_encryption == VerifiedEncryption::Verified if verified_encryption == VerifiedEncryption::Verified
&& mime_parser.get_header(HeaderDef::ChatVerified).is_some() && mime_parser.get_header(HeaderDef::ChatVerified).is_some()
@@ -3059,23 +3062,12 @@ async fn update_verified_keys(
/// Checks whether the message is allowed to appear in a protected chat. /// Checks whether the message is allowed to appear in a protected chat.
/// ///
/// This means that it is encrypted and signed with a verified key. /// This means that it is encrypted and signed with a verified key.
/// fn has_verified_encryption(
/// Also propagates gossiped keys to verified if needed.
async fn has_verified_encryption(
context: &Context,
mimeparser: &MimeMessage, mimeparser: &MimeMessage,
from_id: ContactId, from_id: ContactId,
to_ids: &[ContactId],
) -> Result<VerifiedEncryption> { ) -> Result<VerifiedEncryption> {
use VerifiedEncryption::*; use VerifiedEncryption::*;
// We do not need to check if we are verified with ourself.
let to_ids = to_ids
.iter()
.copied()
.filter(|id| *id != ContactId::SELF)
.collect::<Vec<ContactId>>();
if !mimeparser.was_encrypted() { if !mimeparser.was_encrypted() {
return Ok(NotVerified("This message is not encrypted".to_string())); return Ok(NotVerified("This message is not encrypted".to_string()));
}; };
@@ -3104,21 +3096,24 @@ async fn has_verified_encryption(
} }
} }
mark_recipients_as_verified(context, from_id, to_ids, mimeparser).await?;
Ok(Verified) Ok(Verified)
} }
async fn mark_recipients_as_verified( async fn mark_recipients_as_verified(
context: &Context, context: &Context,
from_id: ContactId, from_id: ContactId,
to_ids: Vec<ContactId>, to_ids: &[ContactId],
mimeparser: &MimeMessage, mimeparser: &MimeMessage,
) -> Result<()> { ) -> Result<()> {
if mimeparser.get_header(HeaderDef::ChatVerified).is_none() { if mimeparser.get_header(HeaderDef::ChatVerified).is_none() {
return Ok(()); return Ok(());
} }
let contact = Contact::get_by_id(context, from_id).await?; let contact = Contact::get_by_id(context, from_id).await?;
for id in to_ids { for &id in to_ids {
if id == ContactId::SELF {
continue;
}
let Some((to_addr, is_verified)) = context let Some((to_addr, is_verified)) = context
.sql .sql
.query_row_optional( .query_row_optional(