From f5e1e2678b24775896cb497ca445e7c18f948941 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 19 Jan 2026 15:07:19 +0100 Subject: [PATCH] fix: Make it possible to leave and immediately delete a chat (#7744) Without this PR, if you leave and immediately delete a chat, the leave message won't be sent. This is needed for https://github.com/deltachat/deltachat-android/issues/4158. --- deltachat-rpc-client/tests/test_something.py | 24 ++++++++++++++++++++ src/chat.rs | 4 ---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index a80bb13b9..c1739c6e5 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -1177,6 +1177,30 @@ def test_leave_broadcast(acfactory, all_devices_online): check_account(bob2, bob2.create_contact(alice), inviter_side=False) +def test_leave_and_delete_group(acfactory, log): + alice, bob = acfactory.get_online_accounts(2) + + log.section("Alice creates a group") + alice_chat = alice.create_group("Group") + alice_chat.add_contact(bob) + assert len(alice_chat.get_contacts()) == 2 # Alice and Bob + alice_chat.send_text("hello") + + log.section("Bob sees the group, and leaves and deletes it") + msg = bob.wait_for_incoming_msg().get_snapshot() + assert msg.text == "hello" + msg.chat.accept() + + msg.chat.leave() + # Bob deletes the chat. This must not prevent the leave message from being sent. + msg.chat.delete() + + log.section("Alice receives the delete message") + # After Bob left, only Alice will be left in the group: + while len(alice_chat.get_contacts()) != 1: + alice.wait_for_event(EventType.CHAT_MODIFIED) + + def test_immediate_autodelete(acfactory, direct_imap, log): ac1, ac2 = acfactory.get_online_accounts(2) diff --git a/src/chat.rs b/src/chat.rs index da07f6c08..97bd8109b 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -635,10 +635,6 @@ impl ChatId { "UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT pre_rfc724_mid FROM msgs WHERE chat_id=? AND pre_rfc724_mid!='')", (&delete_msgs_target, self,), )?; - transaction.execute( - "DELETE FROM smtp WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)", - (self,), - )?; transaction.execute( "DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)", (self,),