mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
fix: do not create ad-hoc groups from partial downloads
This commit is contained in:
@@ -540,25 +540,26 @@ def test_reactions_for_a_reordering_move(acfactory):
|
|||||||
assert list(reactions.reactions_by_contact.values())[0] == [react_str]
|
assert list(reactions.reactions_by_contact.values())[0] == [react_str]
|
||||||
|
|
||||||
|
|
||||||
def test_download_limit_chat_assignment(acfactory, tmp_path):
|
@pytest.mark.parametrize("n_accounts", [3, 2])
|
||||||
|
def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts):
|
||||||
download_limit = 300000
|
download_limit = 300000
|
||||||
alice, bob, carol = acfactory.get_online_accounts(3)
|
|
||||||
|
|
||||||
for account in bob, carol:
|
alice, *others = acfactory.get_online_accounts(n_accounts)
|
||||||
|
bob = others[0]
|
||||||
|
|
||||||
|
alice_group = alice.create_group("test group")
|
||||||
|
for account in others:
|
||||||
chat = account.create_chat(alice)
|
chat = account.create_chat(alice)
|
||||||
chat.send_text("Hello Alice!")
|
chat.send_text("Hello Alice!")
|
||||||
assert alice.get_message_by_id(alice.wait_for_incoming_msg_event().msg_id).get_snapshot().text == "Hello Alice!"
|
assert alice.get_message_by_id(alice.wait_for_incoming_msg_event().msg_id).get_snapshot().text == "Hello Alice!"
|
||||||
|
|
||||||
bob_addr = bob.get_config("addr")
|
contact_addr = account.get_config("addr")
|
||||||
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
|
contact = alice.create_contact(contact_addr, "")
|
||||||
|
|
||||||
carol_addr = carol.get_config("addr")
|
alice_group.add_contact(contact)
|
||||||
alice_contact_carol = alice.create_contact(carol_addr, "Carol")
|
|
||||||
|
|
||||||
alice_group = alice.create_group("test group")
|
|
||||||
alice_group.add_contact(alice_contact_bob)
|
|
||||||
alice_group.add_contact(alice_contact_carol)
|
|
||||||
|
|
||||||
|
if n_accounts == 2:
|
||||||
|
bob_chat_alice = bob.create_chat(alice)
|
||||||
bob.set_config("download_limit", str(download_limit))
|
bob.set_config("download_limit", str(download_limit))
|
||||||
|
|
||||||
alice_group.send_text("hi")
|
alice_group.send_text("hi")
|
||||||
@@ -574,4 +575,12 @@ def test_download_limit_chat_assignment(acfactory, tmp_path):
|
|||||||
alice_group.send_file(str(path))
|
alice_group.send_file(str(path))
|
||||||
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
assert snapshot.download_state == DownloadState.AVAILABLE
|
assert snapshot.download_state == DownloadState.AVAILABLE
|
||||||
assert snapshot.chat == bob_group
|
if n_accounts > 2:
|
||||||
|
assert snapshot.chat == bob_group
|
||||||
|
else:
|
||||||
|
# Group contains only Alice and Bob,
|
||||||
|
# so partially downloaded messages are
|
||||||
|
# hard to distinguish from private replies to group messages.
|
||||||
|
#
|
||||||
|
# Message may be a private reply, so we assign it to 1:1 chat with Alice.
|
||||||
|
assert snapshot.chat == bob_chat_alice
|
||||||
|
|||||||
@@ -1749,7 +1749,19 @@ async fn create_or_lookup_group(
|
|||||||
) -> Result<Option<(ChatId, Blocked)>> {
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
let grpid = if let Some(grpid) = try_getting_grpid(mime_parser) {
|
let grpid = if let Some(grpid) = try_getting_grpid(mime_parser) {
|
||||||
grpid
|
grpid
|
||||||
} else if allow_creation {
|
} else if !allow_creation {
|
||||||
|
info!(context, "Creating ad-hoc group prevented from caller.");
|
||||||
|
return Ok(None);
|
||||||
|
} else if is_partial_download {
|
||||||
|
// Partial download may be an encrypted message with protected Subject header.
|
||||||
|
//
|
||||||
|
// We do not want to create a group with "..." or "Encrypted message" as a subject.
|
||||||
|
info!(
|
||||||
|
context,
|
||||||
|
"Ad-hoc group cannot be created from partial download."
|
||||||
|
);
|
||||||
|
return Ok(None);
|
||||||
|
} else {
|
||||||
let mut member_ids: Vec<ContactId> = to_ids.to_vec();
|
let mut member_ids: Vec<ContactId> = to_ids.to_vec();
|
||||||
if !member_ids.contains(&(from_id)) {
|
if !member_ids.contains(&(from_id)) {
|
||||||
member_ids.push(from_id);
|
member_ids.push(from_id);
|
||||||
@@ -1763,9 +1775,6 @@ async fn create_or_lookup_group(
|
|||||||
.context("could not create ad hoc group")?
|
.context("could not create ad hoc group")?
|
||||||
.map(|chat_id| (chat_id, create_blocked));
|
.map(|chat_id| (chat_id, create_blocked));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
} else {
|
|
||||||
info!(context, "Creating ad-hoc group prevented from caller.");
|
|
||||||
return Ok(None);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut chat_id;
|
let mut chat_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user