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:
link2xt
2025-08-18 08:40:07 +00:00
committed by l
parent 1b6450b210
commit 66c9982822
7 changed files with 38 additions and 24 deletions

View File

@@ -406,7 +406,7 @@ def test_forward_messages(acfactory, lp):
lp.sec("ac2: check new chat has a forwarded message") lp.sec("ac2: check new chat has a forwarded message")
assert chat3.is_promoted() assert chat3.is_promoted()
messages = chat3.get_messages() messages = chat3.get_messages()
assert len(messages) == 2 assert len(messages) == 3
msg = messages[-1] msg = messages[-1]
assert msg.is_forwarded() assert msg.is_forwarded()
ac2.delete_messages(messages) ac2.delete_messages(messages)

View File

@@ -663,4 +663,4 @@ class TestOfflineChat:
lp.sec("check message count of only system messages (without daymarkers)") lp.sec("check message count of only system messages (without daymarkers)")
sysmessages = [x for x in chat.get_messages() if x.is_system_message()] sysmessages = [x for x in chat.get_messages() if x.is_system_message()]
assert len(sysmessages) == 3 assert len(sysmessages) == 4

View File

@@ -3740,11 +3740,19 @@ pub async fn create_group_ex(
chatlist_events::emit_chatlist_changed(context); chatlist_events::emit_chatlist_changed(context);
chatlist_events::emit_chatlist_item_changed(context, chat_id); chatlist_events::emit_chatlist_item_changed(context, chat_id);
if encryption == Some(ProtectionStatus::Protected) { match encryption {
let protect = ProtectionStatus::Protected; Some(ProtectionStatus::Protected) => {
chat_id let protect = ProtectionStatus::Protected;
.set_protection_for_timestamp_sort(context, protect, timestamp, None) chat_id
.await?; .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? if !context.get_config_bool(Config::Bot).await?

View File

@@ -11,7 +11,9 @@ use crate::test_utils::{
AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, E2EE_INFO_MSGS, TestContext, TestContextManager, AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, E2EE_INFO_MSGS, TestContext, TestContextManager,
TimeShiftFalsePositiveNote, sync, TimeShiftFalsePositiveNote, sync,
}; };
use crate::tools::SystemTime;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::time::Duration;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use tokio::fs; use tokio::fs;
@@ -1644,7 +1646,7 @@ async fn test_set_mute_duration() {
async fn test_add_info_msg() -> Result<()> { async fn test_add_info_msg() -> Result<()> {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").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; let msg = t.get_last_msg_in(chat_id).await;
assert_eq!(msg.get_chat_id(), chat_id); assert_eq!(msg.get_chat_id(), chat_id);
@@ -1666,7 +1668,7 @@ async fn test_add_info_msg_with_cmd() -> Result<()> {
chat_id, chat_id,
"foo bar info", "foo bar info",
SystemMessage::EphemeralTimerChanged, SystemMessage::EphemeralTimerChanged,
10000, time(),
None, None,
None, None,
None, None,

View File

@@ -488,6 +488,8 @@ mod tests {
use crate::stock_str::StockMessage; use crate::stock_str::StockMessage;
use crate::test_utils::TestContext; use crate::test_utils::TestContext;
use crate::test_utils::TestContextManager; use crate::test_utils::TestContextManager;
use crate::tools::SystemTime;
use std::time::Duration;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_try_load() { 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(1).unwrap(), chat_id2);
assert_eq!(chats.get_chat_id(2).unwrap(), chat_id1); assert_eq!(chats.get_chat_id(2).unwrap(), chat_id1);
SystemTime::shift(Duration::from_secs(5));
// New drafts are sorted to the top // New drafts are sorted to the top
// We have to set a draft on the other two messages, too, as // 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 // chat timestamps are only exact to the second and sorting by timestamp

View File

@@ -177,7 +177,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
.await?, .await?,
r#"[{"payload":42,"info":"foo","document":"doc","summary":"bar","serial":1,"max_serial":1}]"# 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) let info = Message::load_from_db(&t, instance.id)
.await? .await?
.get_webxdc_info(&t) .get_webxdc_info(&t)
@@ -194,7 +194,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
.await?, .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) let info = Message::load_from_db(&t, instance2.id)
.await? .await?
.get_webxdc_info(&t) .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?; alice.set_config_bool(Config::BccSelf, false).await?;
let alice_grp = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp").await?; let alice_grp = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp").await?;
let alice_instance = send_webxdc_instance(&alice, alice_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 alice
.send_webxdc_status_update( .send_webxdc_status_update(
alice_instance.id, alice_instance.id,
r#"{"payload":7,"info": "i","summary":"s"}"#, r#"{"payload":7,"info": "i","summary":"s"}"#,
) )
.await?; .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()); assert!(alice.get_last_msg_in(alice_grp).await.is_info());
// Alice adds Bob and resends already used webxdc // 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, alice.add_or_lookup_contact_id(&bob).await,
) )
.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?; resend_msgs(&alice, &[alice_instance.id]).await?;
let sent1 = alice.pop_sent_msg().await; let sent1 = alice.pop_sent_msg().await;
alice.flush_status_updates().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}"#) t.send_webxdc_status_update(instance.id, r#"{"info":"i1", "payload":1}"#)
.await?; .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?; 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}"#) t.send_webxdc_status_update(instance.id, r#"{"info":"i2", "payload":2}"#)
.await?; .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(()) Ok(())
} }
@@ -2195,6 +2195,5 @@ async fn test_self_addr_consistency() -> Result<()> {
let sent = alice.send_msg(alice_chat, &mut instance).await; let sent = alice.send_msg(alice_chat, &mut instance).await;
let db_msg = Message::load_from_db(alice, sent.sender_msg_id).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!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
assert_eq!(alice_chat.get_msg_cnt(alice).await?, 1);
Ok(()) Ok(())
} }

View File

@@ -1,9 +1,10 @@
Group#Chat#10: Group [5 member(s)] Group#Chat#10: Group [5 member(s)]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Msg#10🔒: Me (Contact#Contact#Self): populate √ Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
Msg#11: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO] Msg#11🔒: Me (Contact#Contact#Self): populate √
Msg#12: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO] Msg#12: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO]
Msg#13🔒: (Contact#Contact#10): Member elena@example.net added by bob@example.net. [FRESH][INFO] Msg#13: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO]
Msg#14🔒: Me (Contact#Contact#Self): You added member fiona@example.net. [INFO] o Msg#14🔒: (Contact#Contact#10): Member elena@example.net added by bob@example.net. [FRESH][INFO]
Msg#15🔒: (Contact#Contact#10): Member fiona@example.net removed by bob@example.net. [FRESH][INFO] Msg#15🔒: Me (Contact#Contact#Self): You added member fiona@example.net. [INFO] o
Msg#16🔒: (Contact#Contact#10): Member fiona@example.net removed by bob@example.net. [FRESH][INFO]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------