diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 927f1dd37..c8526e68d 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -406,7 +406,7 @@ def test_forward_messages(acfactory, lp): lp.sec("ac2: check new chat has a forwarded message") assert chat3.is_promoted() messages = chat3.get_messages() - assert len(messages) == 2 + assert len(messages) == 3 msg = messages[-1] assert msg.is_forwarded() ac2.delete_messages(messages) diff --git a/python/tests/test_3_offline.py b/python/tests/test_3_offline.py index 850baba71..104041b00 100644 --- a/python/tests/test_3_offline.py +++ b/python/tests/test_3_offline.py @@ -663,4 +663,4 @@ class TestOfflineChat: lp.sec("check message count of only system messages (without daymarkers)") sysmessages = [x for x in chat.get_messages() if x.is_system_message()] - assert len(sysmessages) == 3 + assert len(sysmessages) == 4 diff --git a/src/chat.rs b/src/chat.rs index 92a5180e3..3ba491ceb 100644 --- a/src/chat.rs +++ b/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? diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 64651f583..b2124f941 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -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, diff --git a/src/chatlist.rs b/src/chatlist.rs index 423a30ea9..4e3090c5c 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -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 diff --git a/src/webxdc/webxdc_tests.rs b/src/webxdc/webxdc_tests.rs index 35039459e..d08ad2b30 100644 --- a/src/webxdc/webxdc_tests.rs +++ b/src/webxdc/webxdc_tests.rs @@ -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(()) } diff --git a/test-data/golden/receive_imf_delayed_removal_is_ignored b/test-data/golden/receive_imf_delayed_removal_is_ignored index 43c918f7f..edcf03c1e 100644 --- a/test-data/golden/receive_imf_delayed_removal_is_ignored +++ b/test-data/golden/receive_imf_delayed_removal_is_ignored @@ -1,9 +1,10 @@ Group#Chat#10: Group [5 member(s)] -------------------------------------------------------------------------------- -Msg#10🔒: Me (Contact#Contact#Self): populate √ -Msg#11: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO] -Msg#12: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO] -Msg#13🔒: (Contact#Contact#10): Member elena@example.net added by bob@example.net. [FRESH][INFO] -Msg#14🔒: Me (Contact#Contact#Self): You added member fiona@example.net. [INFO] o -Msg#15🔒: (Contact#Contact#10): Member fiona@example.net removed by bob@example.net. [FRESH][INFO] +Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#11🔒: Me (Contact#Contact#Self): populate √ +Msg#12: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO] +Msg#13: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO] +Msg#14🔒: (Contact#Contact#10): Member elena@example.net added 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] --------------------------------------------------------------------------------