diff --git a/src/chat.rs b/src/chat.rs index 7f49a4ace..e6c1fa5a1 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3697,8 +3697,13 @@ pub async fn create_group_ex( encryption: Option, name: &str, ) -> Result { - let chat_name = sanitize_single_line(name); - ensure!(!chat_name.is_empty(), "Invalid chat name"); + let mut chat_name = sanitize_single_line(name); + if chat_name.is_empty() { + // We can't just fail because the user would lose the work already done in the UI like + // selecting members. + error!(context, "Invalid chat name: {name}."); + chat_name = "…".to_string(); + } let grpid = match encryption { Some(_) => create_id(), diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index e9980f97e..34f1775ea 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -4749,6 +4749,16 @@ async fn test_create_unencrypted_group_chat() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_create_group_invalid_name() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let chat_id = create_group_ex(alice, None, " ").await?; + let chat = Chat::load_from_db(alice, chat_id).await?; + assert_eq!(chat.get_name(), "…"); + Ok(()) +} + /// Tests that avatar cannot be set in ad hoc groups. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_no_avatar_in_adhoc_chats() -> Result<()> {