From d4b1f8694f4b4559e3d473c83a170cf21fe7476b Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 20 Jan 2025 15:54:17 +0100 Subject: [PATCH] fix: Don't accidentally remove Self from groups (#6455) --- src/mimefactory.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 6a78a668f..423e65bdc 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -206,7 +206,7 @@ impl MimeFactory { "SELECT c.authname, c.addr, c.id, cc.add_timestamp, cc.remove_timestamp FROM chats_contacts cc LEFT JOIN contacts c ON cc.contact_id=c.id - WHERE cc.chat_id=? AND cc.contact_id>9 OR (cc.contact_id=1 AND ?)", + WHERE cc.chat_id=? AND (cc.contact_id>9 OR (cc.contact_id=1 AND ?))", (msg.chat_id, chat.typ == Chattype::Group), |row| { let authname: String = row.get(0)?; @@ -2642,4 +2642,40 @@ mod tests { Ok(()) } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_dont_remove_self() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + let first_group = alice + .create_group_with_members(ProtectionStatus::Unprotected, "First group", &[bob]) + .await; + alice.send_text(first_group, "Hi! I created a group.").await; + remove_contact_from_chat(alice, first_group, ContactId::SELF).await?; + alice.pop_sent_msg().await; + + let second_group = alice + .create_group_with_members(ProtectionStatus::Unprotected, "First group", &[bob]) + .await; + let sent = alice + .send_text(second_group, "Hi! I created another group.") + .await; + + println!("{}", sent.payload); + let mime_message = MimeMessage::from_bytes(alice, sent.payload.as_bytes(), None) + .await + .unwrap(); + assert_eq!( + mime_message.get_header(HeaderDef::ChatGroupPastMembers), + None + ); + assert_eq!( + mime_message.chat_group_member_timestamps().unwrap().len(), + 1 // There is a timestamp for Bob, not for Alice + ); + + Ok(()) + } }