mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
fix: add "Messages are end-to-end encrypted." to non-protected groups
The messages are end-to-end encrypted in encrypted group regardless of whether the group is protected or not.
This commit is contained in:
18
src/chat.rs
18
src/chat.rs
@@ -3740,11 +3740,19 @@ pub async fn create_group_ex(
|
||||
chatlist_events::emit_chatlist_changed(context);
|
||||
chatlist_events::emit_chatlist_item_changed(context, chat_id);
|
||||
|
||||
if encryption == Some(ProtectionStatus::Protected) {
|
||||
let protect = ProtectionStatus::Protected;
|
||||
chat_id
|
||||
.set_protection_for_timestamp_sort(context, protect, timestamp, None)
|
||||
.await?;
|
||||
match encryption {
|
||||
Some(ProtectionStatus::Protected) => {
|
||||
let protect = ProtectionStatus::Protected;
|
||||
chat_id
|
||||
.set_protection_for_timestamp_sort(context, protect, timestamp, None)
|
||||
.await?;
|
||||
}
|
||||
Some(ProtectionStatus::Unprotected) => {
|
||||
// Add "Messages are end-to-end encrypted." message
|
||||
// even to unprotected chats.
|
||||
chat_id.maybe_add_encrypted_msg(context, timestamp).await?;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
if !context.get_config_bool(Config::Bot).await?
|
||||
|
||||
@@ -11,7 +11,9 @@ use crate::test_utils::{
|
||||
AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, E2EE_INFO_MSGS, TestContext, TestContextManager,
|
||||
TimeShiftFalsePositiveNote, sync,
|
||||
};
|
||||
use crate::tools::SystemTime;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::time::Duration;
|
||||
use strum::IntoEnumIterator;
|
||||
use tokio::fs;
|
||||
|
||||
@@ -1644,7 +1646,7 @@ async fn test_set_mute_duration() {
|
||||
async fn test_add_info_msg() -> Result<()> {
|
||||
let t = TestContext::new().await;
|
||||
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
|
||||
add_info_msg(&t, chat_id, "foo info", 200000).await?;
|
||||
add_info_msg(&t, chat_id, "foo info", time()).await?;
|
||||
|
||||
let msg = t.get_last_msg_in(chat_id).await;
|
||||
assert_eq!(msg.get_chat_id(), chat_id);
|
||||
@@ -1666,7 +1668,7 @@ async fn test_add_info_msg_with_cmd() -> Result<()> {
|
||||
chat_id,
|
||||
"foo bar info",
|
||||
SystemMessage::EphemeralTimerChanged,
|
||||
10000,
|
||||
time(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -488,6 +488,8 @@ mod tests {
|
||||
use crate::stock_str::StockMessage;
|
||||
use crate::test_utils::TestContext;
|
||||
use crate::test_utils::TestContextManager;
|
||||
use crate::tools::SystemTime;
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_try_load() {
|
||||
@@ -510,6 +512,8 @@ mod tests {
|
||||
assert_eq!(chats.get_chat_id(1).unwrap(), chat_id2);
|
||||
assert_eq!(chats.get_chat_id(2).unwrap(), chat_id1);
|
||||
|
||||
SystemTime::shift(Duration::from_secs(5));
|
||||
|
||||
// New drafts are sorted to the top
|
||||
// We have to set a draft on the other two messages, too, as
|
||||
// chat timestamps are only exact to the second and sorting by timestamp
|
||||
|
||||
@@ -177,7 +177,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
|
||||
.await?,
|
||||
r#"[{"payload":42,"info":"foo","document":"doc","summary":"bar","serial":1,"max_serial":1}]"#
|
||||
);
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 2); // instance and info
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3); // "Messages are end-to-end encrypted", instance and info
|
||||
let info = Message::load_from_db(&t, instance.id)
|
||||
.await?
|
||||
.get_webxdc_info(&t)
|
||||
@@ -194,7 +194,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
|
||||
.await?,
|
||||
"[]"
|
||||
);
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3); // two instances, only one info
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 4); // "Messages are end-to-end encrypted", two instances, only one info
|
||||
let info = Message::load_from_db(&t, instance2.id)
|
||||
.await?
|
||||
.get_webxdc_info(&t)
|
||||
@@ -215,14 +215,14 @@ async fn test_resend_webxdc_instance_and_info() -> Result<()> {
|
||||
alice.set_config_bool(Config::BccSelf, false).await?;
|
||||
let alice_grp = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp").await?;
|
||||
let alice_instance = send_webxdc_instance(&alice, alice_grp).await?;
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 1);
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 2);
|
||||
alice
|
||||
.send_webxdc_status_update(
|
||||
alice_instance.id,
|
||||
r#"{"payload":7,"info": "i","summary":"s"}"#,
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 2);
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 3);
|
||||
assert!(alice.get_last_msg_in(alice_grp).await.is_info());
|
||||
|
||||
// Alice adds Bob and resends already used webxdc
|
||||
@@ -232,7 +232,7 @@ async fn test_resend_webxdc_instance_and_info() -> Result<()> {
|
||||
alice.add_or_lookup_contact_id(&bob).await,
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 3);
|
||||
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 4);
|
||||
resend_msgs(&alice, &[alice_instance.id]).await?;
|
||||
let sent1 = alice.pop_sent_msg().await;
|
||||
alice.flush_status_updates().await?;
|
||||
@@ -1606,12 +1606,12 @@ async fn test_webxdc_info_msg_no_cleanup_on_interrupted_series() -> Result<()> {
|
||||
|
||||
t.send_webxdc_status_update(instance.id, r#"{"info":"i1", "payload":1}"#)
|
||||
.await?;
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 2);
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 2);
|
||||
send_text_msg(&t, chat_id, "msg between info".to_string()).await?;
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3);
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 3);
|
||||
t.send_webxdc_status_update(instance.id, r#"{"info":"i2", "payload":2}"#)
|
||||
.await?;
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 4);
|
||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 4);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -2195,6 +2195,5 @@ async fn test_self_addr_consistency() -> Result<()> {
|
||||
let sent = alice.send_msg(alice_chat, &mut instance).await;
|
||||
let db_msg = Message::load_from_db(alice, sent.sender_msg_id).await?;
|
||||
assert_eq!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
|
||||
assert_eq!(alice_chat.get_msg_cnt(alice).await?, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user