Skip to content

Commit df9e065

Browse files
committed
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.
1 parent 5289945 commit df9e065

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

src/chat.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,11 +3731,19 @@ pub async fn create_group_ex(
37313731
chatlist_events::emit_chatlist_changed(context);
37323732
chatlist_events::emit_chatlist_item_changed(context, chat_id);
37333733

3734-
if encryption == Some(ProtectionStatus::Protected) {
3735-
let protect = ProtectionStatus::Protected;
3736-
chat_id
3737-
.set_protection_for_timestamp_sort(context, protect, timestamp, None)
3738-
.await?;
3734+
match encryption {
3735+
Some(ProtectionStatus::Protected) => {
3736+
let protect = ProtectionStatus::Protected;
3737+
chat_id
3738+
.set_protection_for_timestamp_sort(context, protect, timestamp, None)
3739+
.await?;
3740+
}
3741+
Some(ProtectionStatus::Unprotected) => {
3742+
// Add "Messages are end-to-end encrypted." message
3743+
// even to unprotected chats.
3744+
chat_id.maybe_add_encrypted_msg(context, timestamp).await?;
3745+
}
3746+
None => {}
37393747
}
37403748

37413749
if !context.get_config_bool(Config::Bot).await?

src/chat/chat_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use crate::test_utils::{
1111
AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, E2EE_INFO_MSGS, TestContext, TestContextManager,
1212
TimeShiftFalsePositiveNote, sync,
1313
};
14+
use crate::tools::SystemTime;
1415
use pretty_assertions::assert_eq;
16+
use std::time::Duration;
1517
use strum::IntoEnumIterator;
1618
use tokio::fs;
1719

@@ -1644,7 +1646,7 @@ async fn test_set_mute_duration() {
16441646
async fn test_add_info_msg() -> Result<()> {
16451647
let t = TestContext::new().await;
16461648
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
1647-
add_info_msg(&t, chat_id, "foo info", 200000).await?;
1649+
add_info_msg(&t, chat_id, "foo info", time()).await?;
16481650

16491651
let msg = t.get_last_msg_in(chat_id).await;
16501652
assert_eq!(msg.get_chat_id(), chat_id);
@@ -1666,7 +1668,7 @@ async fn test_add_info_msg_with_cmd() -> Result<()> {
16661668
chat_id,
16671669
"foo bar info",
16681670
SystemMessage::EphemeralTimerChanged,
1669-
10000,
1671+
time(),
16701672
None,
16711673
None,
16721674
None,

src/chatlist.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ mod tests {
488488
use crate::stock_str::StockMessage;
489489
use crate::test_utils::TestContext;
490490
use crate::test_utils::TestContextManager;
491+
use crate::tools::SystemTime;
492+
use std::time::Duration;
491493

492494
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
493495
async fn test_try_load() {
@@ -510,6 +512,8 @@ mod tests {
510512
assert_eq!(chats.get_chat_id(1).unwrap(), chat_id2);
511513
assert_eq!(chats.get_chat_id(2).unwrap(), chat_id1);
512514

515+
SystemTime::shift(Duration::from_secs(5));
516+
513517
// New drafts are sorted to the top
514518
// We have to set a draft on the other two messages, too, as
515519
// chat timestamps are only exact to the second and sorting by timestamp

src/webxdc/webxdc_tests.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
177177
.await?,
178178
r#"[{"payload":42,"info":"foo","document":"doc","summary":"bar","serial":1,"max_serial":1}]"#
179179
);
180-
assert_eq!(chat_id.get_msg_cnt(&t).await?, 2); // instance and info
180+
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3); // "Messages are end-to-end encrypted", instance and info
181181
let info = Message::load_from_db(&t, instance.id)
182182
.await?
183183
.get_webxdc_info(&t)
@@ -194,7 +194,7 @@ async fn test_forward_webxdc_instance() -> Result<()> {
194194
.await?,
195195
"[]"
196196
);
197-
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3); // two instances, only one info
197+
assert_eq!(chat_id.get_msg_cnt(&t).await?, 4); // "Messages are end-to-end encrypted", two instances, only one info
198198
let info = Message::load_from_db(&t, instance2.id)
199199
.await?
200200
.get_webxdc_info(&t)
@@ -215,14 +215,14 @@ async fn test_resend_webxdc_instance_and_info() -> Result<()> {
215215
alice.set_config_bool(Config::BccSelf, false).await?;
216216
let alice_grp = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp").await?;
217217
let alice_instance = send_webxdc_instance(&alice, alice_grp).await?;
218-
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 1);
218+
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 2);
219219
alice
220220
.send_webxdc_status_update(
221221
alice_instance.id,
222222
r#"{"payload":7,"info": "i","summary":"s"}"#,
223223
)
224224
.await?;
225-
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 2);
225+
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 3);
226226
assert!(alice.get_last_msg_in(alice_grp).await.is_info());
227227

228228
// Alice adds Bob and resends already used webxdc
@@ -232,7 +232,7 @@ async fn test_resend_webxdc_instance_and_info() -> Result<()> {
232232
alice.add_or_lookup_contact_id(&bob).await,
233233
)
234234
.await?;
235-
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 3);
235+
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 4);
236236
resend_msgs(&alice, &[alice_instance.id]).await?;
237237
let sent1 = alice.pop_sent_msg().await;
238238
alice.flush_status_updates().await?;
@@ -1606,12 +1606,12 @@ async fn test_webxdc_info_msg_no_cleanup_on_interrupted_series() -> Result<()> {
16061606

16071607
t.send_webxdc_status_update(instance.id, r#"{"info":"i1", "payload":1}"#)
16081608
.await?;
1609-
assert_eq!(chat_id.get_msg_cnt(&t).await?, 2);
1609+
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 2);
16101610
send_text_msg(&t, chat_id, "msg between info".to_string()).await?;
1611-
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3);
1611+
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 3);
16121612
t.send_webxdc_status_update(instance.id, r#"{"info":"i2", "payload":2}"#)
16131613
.await?;
1614-
assert_eq!(chat_id.get_msg_cnt(&t).await?, 4);
1614+
assert_eq!(chat_id.get_msg_cnt(&t).await?, E2EE_INFO_MSGS + 4);
16151615

16161616
Ok(())
16171617
}
@@ -2195,6 +2195,5 @@ async fn test_self_addr_consistency() -> Result<()> {
21952195
let sent = alice.send_msg(alice_chat, &mut instance).await;
21962196
let db_msg = Message::load_from_db(alice, sent.sender_msg_id).await?;
21972197
assert_eq!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
2198-
assert_eq!(alice_chat.get_msg_cnt(alice).await?, 1);
21992198
Ok(())
22002199
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Group#Chat#10: Group [5 member(s)]
22
--------------------------------------------------------------------------------
3-
Msg#10🔒: Me (Contact#Contact#Self): populate √
4-
Msg#11: info (Contact#Contact#Info): Member [email protected] added. [NOTICED][INFO]
5-
Msg#12: info (Contact#Contact#Info): Member [email protected] removed. [NOTICED][INFO]
6-
Msg#13🔒: (Contact#Contact#10): Member [email protected] added by [email protected]. [FRESH][INFO]
7-
Msg#14🔒: Me (Contact#Contact#Self): You added member [email protected]. [INFO] o
8-
Msg#15🔒: (Contact#Contact#10): Member [email protected] removed by [email protected]. [FRESH][INFO]
3+
Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
4+
Msg#11🔒: Me (Contact#Contact#Self): populate √
5+
Msg#12: info (Contact#Contact#Info): Member [email protected] added. [NOTICED][INFO]
6+
Msg#13: info (Contact#Contact#Info): Member [email protected] removed. [NOTICED][INFO]
7+
Msg#14🔒: (Contact#Contact#10): Member [email protected] added by [email protected]. [FRESH][INFO]
8+
Msg#15🔒: Me (Contact#Contact#Self): You added member [email protected]. [INFO] o
9+
Msg#16🔒: (Contact#Contact#10): Member [email protected] removed by [email protected]. [FRESH][INFO]
910
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)