From ff7023580f485f607ed5d7820543276eda338544 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 23 Feb 2026 12:37:48 +0100 Subject: [PATCH] fix: If there was no chat description, and it's set to be an empty string, don't send out a "chat description changed" message (#7879) fix #7877 The bug was: If there is no chat description, and the chat description is set to an empty string, the INSERT statement inserted a row with an empty chat description, and therefore from the view of the INSERT statement, something changed. This PR fixes this by simply loading the chat description first, and comparing it. --- src/chat.rs | 15 +++++++-------- src/chat/chat_tests.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 546f069d7..937ae8669 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4248,20 +4248,19 @@ async fn set_chat_description_ex( bail!("Cannot set chat description; self not in group"); } - let affected_rows = context + let old_description = get_chat_description(context, chat_id).await?; + if old_description == new_description { + return Ok(()); + } + + context .sql .execute( - "INSERT INTO chats_descriptions(chat_id, description) VALUES(?, ?) - ON CONFLICT(chat_id) DO UPDATE - SET description=excluded.description WHERE description<>excluded.description", + "INSERT OR REPLACE INTO chats_descriptions(chat_id, description) VALUES(?, ?)", (chat_id, &new_description), ) .await?; - if affected_rows == 0 { - return Ok(()); - } - if chat.is_promoted() { let mut msg = Message::new(Viewtype::Text); msg.text = diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 66b444fc0..4f5fe911f 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -3269,6 +3269,36 @@ async fn test_chat_description(initial_description: &str, join_via_qr: bool) -> Ok(()) } +/// Tests explicitly setting an empty chat description +/// doesn't trigger sending out a message +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_setting_empty_chat_description() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + tcm.section("Create a group chat, and add Bob in order to promote it"); + let alice_chat_id = create_group(alice, "My Group").await?; + + add_contact_to_chat( + alice, + alice_chat_id, + alice.add_or_lookup_contact_id(bob).await, + ) + .await?; + let _hi = alice.send_text(alice_chat_id, "hi").await; + + set_chat_description(alice, alice_chat_id, "").await?; + assert!( + alice + .pop_sent_msg_opt(Duration::from_secs(0)) + .await + .is_none() + ); + + Ok(()) +} + /// Tests that directly after broadcast-securejoin, /// the brodacast is shown correctly on both devices. #[tokio::test(flavor = "multi_thread", worker_threads = 2)]