diff --git a/src/chat.rs b/src/chat.rs index e4eb43097..265710680 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4235,11 +4235,16 @@ async fn rename_ex( (new_name.to_string(), chat_id), ) .await?; - if chat.is_promoted() - && !chat.is_mailing_list() - && chat.typ != Chattype::Broadcast - && sanitize_single_line(&chat.name) != new_name + if !chat.is_promoted() + || chat.is_mailing_list() + || chat.typ == Chattype::Broadcast + || sanitize_single_line(&chat.name) == new_name { + } else if chat.grpid.is_empty() { + chat_id + .update_timestamp(context, Param::GroupNameTimestamp, smeared_time(context)) + .await?; + } else { msg.viewtype = Viewtype::Text; msg.text = stock_str::msg_grp_name(context, &chat.name, &new_name, ContactId::SELF).await; diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 5b1ce99e6..fd1838bf7 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -4455,6 +4455,43 @@ async fn test_mua_can_readd() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_rename_unencrypted_group() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + for ctx in [alice, bob] { + receive_imf( + ctx, + b"Subject: Some thread\r\n\ + From: alice@example.org\r\n\ + To: , \r\n\ + Date: Mon, 12 Dec 2022 14:30:39 +0000\r\n\ + Message-ID: \r\n\ + Chat-Version: 1.0\r\n\ + \r\n\ + Hi!\r\n", + false, + ) + .await? + .unwrap(); + } + let msg = alice.get_last_msg().await; + let alice_chat = Chat::load_from_db(alice, msg.chat_id).await?; + assert_eq!(alice_chat.typ, Chattype::Group); + + SystemTime::shift(Duration::from_secs(60)); + chat::set_chat_name(alice, alice_chat.id, "Renamed thread").await?; + assert!(!alice.sql.exists("SELECT COUNT(*) FROM smtp", ()).await?); + + let sent_msg = alice.send_text(alice_chat.id, "I renamed the thread").await; + let msg = bob.recv_msg(&sent_msg).await; + let bob_chat = Chat::load_from_db(bob, msg.chat_id).await?; + assert_eq!(bob_chat.get_name(), "Renamed thread"); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_member_left_does_not_create_chat() -> Result<()> { let mut tcm = TestContextManager::new();