mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 14:26:30 +03:00
api!: remove APIs to create protected chats
Create unprotected group in test_create_protected_grp_multidev The test is renamed accordingly. SystemMessage::ChatE2ee is added in encrypted groups regardless of whether they are protected or not. Previously new encrypted unprotected groups had no message saying that messages are end-to-end encrypted at all.
This commit is contained in:
@@ -14,9 +14,7 @@ use mailparse::SingleInfo;
|
||||
use num_traits::FromPrimitive;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::chat::{
|
||||
self, Chat, ChatId, ChatIdBlocked, ProtectionStatus, remove_from_chat_contacts_table,
|
||||
};
|
||||
use crate::chat::{self, Chat, ChatId, ChatIdBlocked, remove_from_chat_contacts_table};
|
||||
use crate::config::Config;
|
||||
use crate::constants::{self, Blocked, Chattype, DC_CHAT_ID_TRASH, EDITED_PREFIX, ShowEmails};
|
||||
use crate::contact::{Contact, ContactId, Origin, mark_contact_id_as_verified};
|
||||
@@ -794,7 +792,6 @@ pub(crate) async fn receive_imf_inner(
|
||||
allow_creation,
|
||||
&mut mime_parser,
|
||||
is_partial_download,
|
||||
&verified_encryption,
|
||||
parent_message,
|
||||
)
|
||||
.await?;
|
||||
@@ -812,7 +809,6 @@ pub(crate) async fn receive_imf_inner(
|
||||
is_partial_download,
|
||||
replace_msg_id,
|
||||
prevent_rename,
|
||||
verified_encryption,
|
||||
chat_id,
|
||||
chat_id_blocked,
|
||||
is_dc_message,
|
||||
@@ -1319,7 +1315,6 @@ async fn do_chat_assignment(
|
||||
allow_creation: bool,
|
||||
mime_parser: &mut MimeMessage,
|
||||
is_partial_download: Option<u32>,
|
||||
verified_encryption: &VerifiedEncryption,
|
||||
parent_message: Option<Message>,
|
||||
) -> Result<(ChatId, Blocked)> {
|
||||
let is_bot = context.get_config_bool(Config::Bot).await?;
|
||||
@@ -1376,7 +1371,6 @@ async fn do_chat_assignment(
|
||||
from_id,
|
||||
to_ids,
|
||||
past_ids,
|
||||
verified_encryption,
|
||||
grpid,
|
||||
)
|
||||
.await?
|
||||
@@ -1478,45 +1472,6 @@ async fn do_chat_assignment(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
true => Some(Chat::load_from_db(context, chat_id).await?)
|
||||
.filter(|chat| chat.typ == Chattype::Single),
|
||||
false => None,
|
||||
};
|
||||
if let Some(chat) = chat {
|
||||
ensure_and_debug_assert!(
|
||||
chat.typ == Chattype::Single,
|
||||
"Chat {chat_id} is not Single",
|
||||
);
|
||||
let new_protection = match verified_encryption {
|
||||
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
||||
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
||||
};
|
||||
|
||||
ensure_and_debug_assert!(
|
||||
chat.protected == ProtectionStatus::Unprotected
|
||||
|| new_protection == ProtectionStatus::Protected,
|
||||
"Chat {chat_id} can't downgrade to Unprotected",
|
||||
);
|
||||
if chat.protected != new_protection {
|
||||
// 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.
|
||||
chat_id
|
||||
.set_protection(
|
||||
context,
|
||||
new_protection,
|
||||
mime_parser.timestamp_sent,
|
||||
Some(from_id),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1547,7 +1502,6 @@ async fn do_chat_assignment(
|
||||
from_id,
|
||||
to_ids,
|
||||
past_ids,
|
||||
verified_encryption,
|
||||
grpid,
|
||||
)
|
||||
.await?
|
||||
@@ -1669,7 +1623,6 @@ async fn add_parts(
|
||||
is_partial_download: Option<u32>,
|
||||
mut replace_msg_id: Option<MsgId>,
|
||||
prevent_rename: bool,
|
||||
verified_encryption: VerifiedEncryption,
|
||||
chat_id: ChatId,
|
||||
chat_id_blocked: Blocked,
|
||||
is_dc_message: MessengerMessage,
|
||||
@@ -1718,16 +1671,7 @@ async fn add_parts(
|
||||
apply_out_broadcast_changes(context, mime_parser, &mut chat, from_id).await?
|
||||
}
|
||||
Chattype::Group => {
|
||||
apply_group_changes(
|
||||
context,
|
||||
mime_parser,
|
||||
&mut chat,
|
||||
from_id,
|
||||
to_ids,
|
||||
past_ids,
|
||||
&verified_encryption,
|
||||
)
|
||||
.await?
|
||||
apply_group_changes(context, mime_parser, &mut chat, from_id, to_ids, past_ids).await?
|
||||
}
|
||||
Chattype::InBroadcast => {
|
||||
apply_in_broadcast_changes(context, mime_parser, &mut chat, from_id).await?
|
||||
@@ -2632,27 +2576,12 @@ async fn create_group(
|
||||
from_id: ContactId,
|
||||
to_ids: &[Option<ContactId>],
|
||||
past_ids: &[Option<ContactId>],
|
||||
verified_encryption: &VerifiedEncryption,
|
||||
grpid: &str,
|
||||
) -> Result<Option<(ChatId, Blocked)>> {
|
||||
let to_ids_flat: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
|
||||
let mut chat_id = None;
|
||||
let mut chat_id_blocked = Default::default();
|
||||
|
||||
let create_protected = if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
|
||||
if let VerifiedEncryption::NotVerified(err) = verified_encryption {
|
||||
warn!(
|
||||
context,
|
||||
"Creating unprotected group because of the verification problem: {err:#}."
|
||||
);
|
||||
ProtectionStatus::Unprotected
|
||||
} else {
|
||||
ProtectionStatus::Protected
|
||||
}
|
||||
} else {
|
||||
ProtectionStatus::Unprotected
|
||||
};
|
||||
|
||||
async fn self_explicitly_added(
|
||||
context: &Context,
|
||||
mime_parser: &&mut MimeMessage,
|
||||
@@ -2688,7 +2617,6 @@ async fn create_group(
|
||||
grpid,
|
||||
grpname,
|
||||
create_blocked,
|
||||
create_protected,
|
||||
None,
|
||||
mime_parser.timestamp_sent,
|
||||
)
|
||||
@@ -2860,7 +2788,6 @@ async fn apply_group_changes(
|
||||
from_id: ContactId,
|
||||
to_ids: &[Option<ContactId>],
|
||||
past_ids: &[Option<ContactId>],
|
||||
verified_encryption: &VerifiedEncryption,
|
||||
) -> Result<GroupChangesInfo> {
|
||||
let to_ids_flat: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
|
||||
ensure!(chat.typ == Chattype::Group);
|
||||
@@ -2875,24 +2802,6 @@ async fn apply_group_changes(
|
||||
let is_from_in_chat =
|
||||
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
|
||||
|
||||
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() && !chat.is_protected() {
|
||||
if let VerifiedEncryption::NotVerified(err) = verified_encryption {
|
||||
warn!(
|
||||
context,
|
||||
"Not marking chat {} as protected due to verification problem: {err:#}.", chat.id,
|
||||
);
|
||||
} else {
|
||||
chat.id
|
||||
.set_protection(
|
||||
context,
|
||||
ProtectionStatus::Protected,
|
||||
mime_parser.timestamp_sent,
|
||||
Some(from_id),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(removed_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) {
|
||||
// TODO: if address "alice@example.org" is a member of the group twice,
|
||||
// with old and new key,
|
||||
@@ -3318,7 +3227,6 @@ async fn create_or_lookup_mailinglist_or_broadcast(
|
||||
&listid,
|
||||
name,
|
||||
blocked,
|
||||
ProtectionStatus::Unprotected,
|
||||
param,
|
||||
mime_parser.timestamp_sent,
|
||||
)
|
||||
@@ -3599,7 +3507,6 @@ async fn create_adhoc_group(
|
||||
"", // Ad hoc groups have no ID.
|
||||
grpname,
|
||||
create_blocked,
|
||||
ProtectionStatus::Unprotected,
|
||||
None,
|
||||
mime_parser.timestamp_sent,
|
||||
)
|
||||
@@ -3696,7 +3603,6 @@ async fn mark_recipients_as_verified(
|
||||
}
|
||||
|
||||
mark_contact_id_as_verified(context, to_id, verifier_id).await?;
|
||||
ChatId::set_protection_for_contact(context, to_id, mimeparser.timestamp_sent).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user