Skip to content

Commit 2ada3cd

Browse files
committed
fix: stop using leftgrps table
1 parent b920552 commit 2ada3cd

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

deltachat-repl/src/cmdline.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ async fn reset_tables(context: &Context, bits: i32) {
7070
.await
7171
.unwrap();
7272
context.sql().config_cache().write().await.clear();
73-
context
74-
.sql()
75-
.execute("DELETE FROM leftgrps;", ())
76-
.await
77-
.unwrap();
7873
println!("(8) Rest but server config reset.");
7974
}
8075

src/chat.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,7 +3881,6 @@ pub async fn remove_contact_from_chat(
38813881

38823882
if contact_id == ContactId::SELF {
38833883
res?;
3884-
set_group_explicitly_left(context, &chat.grpid).await?;
38853884
} else if let Err(e) = res {
38863885
warn!(
38873886
context,
@@ -3935,25 +3934,6 @@ async fn send_member_removal_msg(
39353934
send_msg(context, chat.id, &mut msg).await
39363935
}
39373936

3938-
async fn set_group_explicitly_left(context: &Context, grpid: &str) -> Result<()> {
3939-
if !is_group_explicitly_left(context, grpid).await? {
3940-
context
3941-
.sql
3942-
.execute("INSERT INTO leftgrps (grpid) VALUES(?);", (grpid,))
3943-
.await?;
3944-
}
3945-
3946-
Ok(())
3947-
}
3948-
3949-
pub(crate) async fn is_group_explicitly_left(context: &Context, grpid: &str) -> Result<bool> {
3950-
let exists = context
3951-
.sql
3952-
.exists("SELECT COUNT(*) FROM leftgrps WHERE grpid=?;", (grpid,))
3953-
.await?;
3954-
Ok(exists)
3955-
}
3956-
39573937
/// Sets group or mailing list chat name.
39583938
pub async fn set_chat_name(context: &Context, chat_id: ChatId, new_name: &str) -> Result<()> {
39593939
rename_ex(context, Sync, chat_id, new_name).await

src/chat/chat_tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,3 +4867,47 @@ async fn test_long_group_name() -> Result<()> {
48674867

48684868
Ok(())
48694869
}
4870+
4871+
/// Regression test for the case
4872+
/// when Bob leaves the group, joins back and deletes the chat.
4873+
/// Previously this resulted in the group
4874+
/// never appearing again without removing Bob
4875+
/// and readding back because the group was
4876+
/// recorded in `leftgrps` for Bob and everyone else
4877+
/// thought that Bob is part of the group.
4878+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
4879+
async fn test_leftgrps() -> Result<()> {
4880+
let mut tcm = TestContextManager::new();
4881+
let alice = &tcm.alice().await;
4882+
let bob = &tcm.bob().await;
4883+
4884+
// Alice creates a group with Bob and Bob accepts it.
4885+
let bob_id = alice.add_or_lookup_contact_id(bob).await;
4886+
let alice_chat_id = create_group(alice, "Group").await?;
4887+
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
4888+
let alice_sent = alice.send_text(alice_chat_id, "Hi!").await;
4889+
let bob_chat_id = bob.recv_msg(&alice_sent).await.chat_id;
4890+
bob_chat_id.accept(bob).await?;
4891+
4892+
// Bob leaves the group.
4893+
remove_contact_from_chat(bob, bob_chat_id, ContactId::SELF).await?;
4894+
let bob_sent = bob.pop_sent_msg().await;
4895+
alice.recv_msg(&bob_sent).await;
4896+
4897+
// Alice adds Bob back, Bob recognizes that the chat is the same.
4898+
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
4899+
let alice_sent = alice.pop_sent_msg().await;
4900+
let bob_chat_id2 = bob.recv_msg(&alice_sent).await.chat_id;
4901+
assert_eq!(bob_chat_id, bob_chat_id2);
4902+
4903+
// Bob deletes the chat.
4904+
bob_chat_id.delete(bob).await?;
4905+
let alice_sent = alice.send_text(alice_chat_id, "Hi again!").await;
4906+
let bob_chat_id3 = bob.recv_msg(&alice_sent).await.chat_id;
4907+
4908+
// Chat ID is new, but not a trash chat.
4909+
assert_ne!(bob_chat_id3, bob_chat_id);
4910+
assert!(!bob_chat_id3.is_special());
4911+
4912+
Ok(())
4913+
}

src/receive_imf.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,26 +2562,12 @@ async fn create_group(
25622562
let mut chat_id = None;
25632563
let mut chat_id_blocked = Default::default();
25642564

2565-
async fn self_explicitly_added(
2566-
context: &Context,
2567-
mime_parser: &&mut MimeMessage,
2568-
) -> Result<bool> {
2569-
let ret = match mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) {
2570-
Some(member_addr) => context.is_self_addr(member_addr).await?,
2571-
None => false,
2572-
};
2573-
Ok(ret)
2574-
}
2575-
25762565
if chat_id.is_none()
25772566
&& !mime_parser.is_mailinglist_message()
25782567
&& !grpid.is_empty()
25792568
&& mime_parser.get_header(HeaderDef::ChatGroupName).is_some()
25802569
// otherwise, a pending "quit" message may pop up
25812570
&& mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved).is_none()
2582-
// re-create explicitly left groups only if ourself is re-added
2583-
&& (!chat::is_group_explicitly_left(context, grpid).await?
2584-
|| self_explicitly_added(context, &mime_parser).await?)
25852571
{
25862572
// Group does not exist but should be created.
25872573
let grpname = mime_parser

0 commit comments

Comments
 (0)