Skip to content

Commit ff6198e

Browse files
committed
fix: Look up or create ad-hoc group if there are duplicate addresses in "To"
Fix `test_unencrypted_doesnt_goto_self_chat` as well, it was only testing the first message because of using the same Message-ID for all messages.
1 parent 57aadfb commit ff6198e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/receive_imf.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,11 +2471,8 @@ async fn lookup_or_create_adhoc_group(
24712471
.unwrap_or_else(|| "👥📧".to_string())
24722472
});
24732473
let to_ids: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
2474-
let mut contact_ids = Vec::with_capacity(to_ids.len() + 1);
2475-
contact_ids.extend(&to_ids);
2476-
if !contact_ids.contains(&from_id) {
2477-
contact_ids.push(from_id);
2478-
}
2474+
let mut contact_ids = BTreeSet::<ContactId>::from_iter(to_ids.iter().copied());
2475+
contact_ids.insert(from_id);
24792476
let trans_fn = |t: &mut rusqlite::Transaction| {
24802477
t.pragma_update(None, "query_only", "0")?;
24812478
t.execute(

src/receive_imf/receive_imf_tests.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,18 +1970,23 @@ Message content",
19701970
async fn test_unencrypted_doesnt_goto_self_chat() -> Result<()> {
19711971
let mut tcm = TestContextManager::new();
19721972
let t = &tcm.alice().await;
1973+
let mut chat_id = None;
19731974

1974-
for to in [
1975+
for (i, to) in [
1976+
19751977
19761978
19771979
"hidden-recipients:;",
1978-
] {
1980+
]
1981+
.iter()
1982+
.enumerate()
1983+
{
19791984
receive_imf(
19801985
t,
19811986
format!(
19821987
"Subject: s
19831988
Chat-Version: 1.0
1984-
Message-ID: <foobar@localhost>
1989+
Message-ID: <foobar{i}@localhost>
19851990
To: {to}
19861991
19871992
@@ -1996,9 +2001,14 @@ Your server is hacked. Have a nice day!"
19962001
assert_ne!(msg.chat_id, t.get_self_chat().await.id);
19972002
assert_eq!(msg.from_id, ContactId::SELF);
19982003
assert_eq!(msg.to_id, ContactId::SELF);
1999-
let chat = Chat::load_from_db(t, msg.chat_id).await?;
2000-
assert_eq!(chat.typ, Chattype::Group);
2001-
assert!(!chat.is_encrypted(t).await?);
2004+
if let Some(chat_id) = chat_id {
2005+
assert_eq!(msg.chat_id, chat_id);
2006+
} else {
2007+
chat_id = Some(msg.chat_id);
2008+
let chat = Chat::load_from_db(t, msg.chat_id).await?;
2009+
assert_eq!(chat.typ, Chattype::Group);
2010+
assert!(!chat.is_encrypted(t).await?);
2011+
}
20022012
}
20032013
Ok(())
20042014
}

0 commit comments

Comments
 (0)