From 11e3480fe847e3045ce955fb4f73ba0cb7fdd88f Mon Sep 17 00:00:00 2001 From: iequidoo Date: Thu, 21 Aug 2025 09:49:48 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20create=5Fgroup=5Fex():=20Log=20and=20re?= =?UTF-8?q?place=20invalid=20chat=20name=20with=20"=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can't just fail on an invalid chat name because the user would lose the work already done in the UI like selecting members. Sometimes happens to me when i put space into name. --- src/chat.rs | 9 +++++++-- src/chat/chat_tests.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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<()> {