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)]