mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
refactor: call has_verified_encryption() in a single place
This centralizes all Securejoin/verification checks and updates in one place right before add_parts() even before we assign the message to the chat, so we can decouple chat logic from verification logic.
This commit is contained in:
@@ -288,6 +288,9 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
received_msg = None;
|
received_msg = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let verified_encryption =
|
||||||
|
has_verified_encryption(context, &mime_parser, from_id, &to_ids).await?;
|
||||||
|
|
||||||
let received_msg = if let Some(received_msg) = received_msg {
|
let received_msg = if let Some(received_msg) = received_msg {
|
||||||
received_msg
|
received_msg
|
||||||
} else {
|
} else {
|
||||||
@@ -307,6 +310,7 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
replace_partial_download,
|
replace_partial_download,
|
||||||
fetching_existing_messages,
|
fetching_existing_messages,
|
||||||
prevent_rename,
|
prevent_rename,
|
||||||
|
verified_encryption,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("add_parts error")?
|
.context("add_parts error")?
|
||||||
@@ -518,6 +522,7 @@ async fn add_parts(
|
|||||||
mut replace_msg_id: Option<MsgId>,
|
mut replace_msg_id: Option<MsgId>,
|
||||||
fetching_existing_messages: bool,
|
fetching_existing_messages: bool,
|
||||||
prevent_rename: bool,
|
prevent_rename: bool,
|
||||||
|
verified_encryption: VerifiedEncryption,
|
||||||
) -> Result<ReceivedMsg> {
|
) -> Result<ReceivedMsg> {
|
||||||
let mut chat_id = None;
|
let mut chat_id = None;
|
||||||
let mut chat_id_blocked = Blocked::Not;
|
let mut chat_id_blocked = Blocked::Not;
|
||||||
@@ -648,6 +653,7 @@ async fn add_parts(
|
|||||||
create_blocked,
|
create_blocked,
|
||||||
from_id,
|
from_id,
|
||||||
to_ids,
|
to_ids,
|
||||||
|
&verified_encryption,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
@@ -698,6 +704,7 @@ async fn add_parts(
|
|||||||
from_id,
|
from_id,
|
||||||
to_ids,
|
to_ids,
|
||||||
is_partial_download.is_some(),
|
is_partial_download.is_some(),
|
||||||
|
&verified_encryption,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -789,12 +796,10 @@ async fn add_parts(
|
|||||||
};
|
};
|
||||||
if let Some(chat) = chat {
|
if let Some(chat) = chat {
|
||||||
debug_assert!(chat.typ == Chattype::Single);
|
debug_assert!(chat.typ == Chattype::Single);
|
||||||
let mut new_protection =
|
let mut new_protection = match verified_encryption {
|
||||||
match has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
||||||
{
|
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
||||||
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
};
|
||||||
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
|
||||||
};
|
|
||||||
|
|
||||||
if chat.protected != ProtectionStatus::Unprotected
|
if chat.protected != ProtectionStatus::Unprotected
|
||||||
&& new_protection == ProtectionStatus::Unprotected
|
&& new_protection == ProtectionStatus::Unprotected
|
||||||
@@ -879,6 +884,7 @@ async fn add_parts(
|
|||||||
Blocked::Not,
|
Blocked::Not,
|
||||||
from_id,
|
from_id,
|
||||||
to_ids,
|
to_ids,
|
||||||
|
&verified_encryption,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
@@ -921,6 +927,7 @@ async fn add_parts(
|
|||||||
from_id,
|
from_id,
|
||||||
to_ids,
|
to_ids,
|
||||||
is_partial_download.is_some(),
|
is_partial_download.is_some(),
|
||||||
|
&verified_encryption,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -1086,9 +1093,7 @@ async fn add_parts(
|
|||||||
let chat = Chat::load_from_db(context, chat_id).await?;
|
let chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
|
|
||||||
if chat.is_protected() {
|
if chat.is_protected() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) = verified_encryption {
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
|
||||||
{
|
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
mime_parser.replace_msg_by_error(&s);
|
mime_parser.replace_msg_by_error(&s);
|
||||||
@@ -1600,6 +1605,7 @@ async fn is_probably_private_reply(
|
|||||||
/// than two members, a new ad hoc group is created.
|
/// than two members, a new ad hoc group is created.
|
||||||
///
|
///
|
||||||
/// On success the function returns the found/created (chat_id, chat_blocked) tuple.
|
/// On success the function returns the found/created (chat_id, chat_blocked) tuple.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn create_or_lookup_group(
|
async fn create_or_lookup_group(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &mut MimeMessage,
|
mime_parser: &mut MimeMessage,
|
||||||
@@ -1608,6 +1614,7 @@ async fn create_or_lookup_group(
|
|||||||
create_blocked: Blocked,
|
create_blocked: Blocked,
|
||||||
from_id: ContactId,
|
from_id: ContactId,
|
||||||
to_ids: &[ContactId],
|
to_ids: &[ContactId],
|
||||||
|
verified_encryption: &VerifiedEncryption,
|
||||||
) -> Result<Option<(ChatId, Blocked)>> {
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
let grpid = if let Some(grpid) = try_getting_grpid(mime_parser) {
|
let grpid = if let Some(grpid) = try_getting_grpid(mime_parser) {
|
||||||
grpid
|
grpid
|
||||||
@@ -1651,9 +1658,7 @@ async fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let create_protected = if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
let create_protected = if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) = verified_encryption {
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
|
||||||
{
|
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
mime_parser.replace_msg_by_error(&s);
|
mime_parser.replace_msg_by_error(&s);
|
||||||
@@ -1746,6 +1751,7 @@ async fn create_or_lookup_group(
|
|||||||
///
|
///
|
||||||
/// Optionally returns better message to replace the original system message.
|
/// Optionally returns better message to replace the original system message.
|
||||||
/// is_partial_download: whether the message is not fully downloaded.
|
/// is_partial_download: whether the message is not fully downloaded.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn apply_group_changes(
|
async fn apply_group_changes(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &mut MimeMessage,
|
mime_parser: &mut MimeMessage,
|
||||||
@@ -1754,6 +1760,7 @@ async fn apply_group_changes(
|
|||||||
from_id: ContactId,
|
from_id: ContactId,
|
||||||
to_ids: &[ContactId],
|
to_ids: &[ContactId],
|
||||||
is_partial_download: bool,
|
is_partial_download: bool,
|
||||||
|
verified_encryption: &VerifiedEncryption,
|
||||||
) -> Result<(Vec<String>, Option<String>)> {
|
) -> Result<(Vec<String>, Option<String>)> {
|
||||||
if chat_id.is_special() {
|
if chat_id.is_special() {
|
||||||
// Do not apply group changes to the trash chat.
|
// Do not apply group changes to the trash chat.
|
||||||
@@ -1814,9 +1821,7 @@ async fn apply_group_changes(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
||||||
if let VerifiedEncryption::NotVerified(err) =
|
if let VerifiedEncryption::NotVerified(err) = verified_encryption {
|
||||||
has_verified_encryption(context, mime_parser, from_id, to_ids).await?
|
|
||||||
{
|
|
||||||
warn!(context, "Verification problem: {err:#}.");
|
warn!(context, "Verification problem: {err:#}.");
|
||||||
let s = format!("{err}. See 'Info' for more details");
|
let s = format!("{err}. See 'Info' for more details");
|
||||||
mime_parser.replace_msg_by_error(&s);
|
mime_parser.replace_msg_by_error(&s);
|
||||||
|
|||||||
Reference in New Issue
Block a user