Skip to content

Commit 11e3480

Browse files
committed
feat: create_group_ex(): Log and replace invalid chat name with "…"
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.
1 parent 2cd54b7 commit 11e3480

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/chat.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,8 +3697,13 @@ pub async fn create_group_ex(
36973697
encryption: Option<ProtectionStatus>,
36983698
name: &str,
36993699
) -> Result<ChatId> {
3700-
let chat_name = sanitize_single_line(name);
3701-
ensure!(!chat_name.is_empty(), "Invalid chat name");
3700+
let mut chat_name = sanitize_single_line(name);
3701+
if chat_name.is_empty() {
3702+
// We can't just fail because the user would lose the work already done in the UI like
3703+
// selecting members.
3704+
error!(context, "Invalid chat name: {name}.");
3705+
chat_name = "…".to_string();
3706+
}
37023707

37033708
let grpid = match encryption {
37043709
Some(_) => create_id(),

src/chat/chat_tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,6 +4749,16 @@ async fn test_create_unencrypted_group_chat() -> Result<()> {
47494749
Ok(())
47504750
}
47514751

4752+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
4753+
async fn test_create_group_invalid_name() -> Result<()> {
4754+
let mut tcm = TestContextManager::new();
4755+
let alice = &tcm.alice().await;
4756+
let chat_id = create_group_ex(alice, None, " ").await?;
4757+
let chat = Chat::load_from_db(alice, chat_id).await?;
4758+
assert_eq!(chat.get_name(), "…");
4759+
Ok(())
4760+
}
4761+
47524762
/// Tests that avatar cannot be set in ad hoc groups.
47534763
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
47544764
async fn test_no_avatar_in_adhoc_chats() -> Result<()> {

0 commit comments

Comments
 (0)