fix: allow creation of groups by outgoing messages without recipients

`!to_ids().is_empty()` check is needed in cases of 1:1 chat creation
because otherwise `to_id` is undefined,
but in case of outgoing group message without recipients
observed on a second device creating a group should be allowed.
This commit is contained in:
link2xt
2024-05-30 13:28:28 +00:00
parent b7e5b906d1
commit 42a7cd3eea
2 changed files with 36 additions and 16 deletions

View File

@@ -1098,7 +1098,6 @@ async fn add_parts(
} }
} }
if !to_ids.is_empty() {
if chat_id.is_none() && allow_creation { if chat_id.is_none() && allow_creation {
if let Some((new_chat_id, new_chat_id_blocked)) = create_group( if let Some((new_chat_id, new_chat_id_blocked)) = create_group(
context, context,
@@ -1115,6 +1114,8 @@ async fn add_parts(
chat_id_blocked = new_chat_id_blocked; chat_id_blocked = new_chat_id_blocked;
} }
} }
if !to_ids.is_empty() {
if chat_id.is_none() && allow_creation { if chat_id.is_none() && allow_creation {
let to_contact = Contact::get_by_id(context, to_id).await?; let to_contact = Contact::get_by_id(context, to_id).await?;
if let Some(list_id) = to_contact.param.get(Param::ListId) { if let Some(list_id) = to_contact.param.get(Param::ListId) {

View File

@@ -4593,3 +4593,22 @@ async fn test_receive_vcard() -> Result<()> {
Ok(()) Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_group_no_recipients() -> Result<()> {
let t = &TestContext::new_alice().await;
let raw = b"From: alice@example.org\n\
Subject: Group\n\
Chat-Version: 1.0\n\
Chat-Group-Name: Group\n\
Chat-Group-ID: GePFDkwEj2K\n\
Message-ID: <foobar@localhost>\n\
\n\
Hello!";
let received = receive_imf(t, raw, false).await?.unwrap();
let msg = Message::load_from_db(t, *received.msg_ids.last().unwrap()).await?;
let chat = Chat::load_from_db(t, msg.chat_id).await?;
assert_eq!(chat.typ, Chattype::Group);
Ok(())
}