From 492ad835ba0ee920e36e70bb003a3a455904e888 Mon Sep 17 00:00:00 2001 From: otsmr Date: Mon, 20 Apr 2026 12:59:29 +0200 Subject: [PATCH] Improved: Username change error handling --- CHANGELOG.md | 1 + .../views/settings/profile/profile.view.dart | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dea3300..a2cbad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.1.6 - Improved: Show input indicator in the chat overview as well +- Improved: Username change error handling - Fix: Phantom push notification - Fix: Start in chat, if configured - Fix: Smaller UI fixes diff --git a/lib/src/views/settings/profile/profile.view.dart b/lib/src/views/settings/profile/profile.view.dart index 89ea84f..fa743e2 100644 --- a/lib/src/views/settings/profile/profile.view.dart +++ b/lib/src/views/settings/profile/profile.view.dart @@ -57,14 +57,28 @@ class _ProfileViewState extends State { } Future _updateUsername(String username) async { - final result = await apiService.changeUsername(username); + var filteredUsername = username.replaceAll( + RegExp('[^a-zA-Z0-9._]'), + '', + ); + + if (filteredUsername.length > 12) { + filteredUsername = filteredUsername.substring(0, 12); + } + + final result = await apiService.changeUsername(filteredUsername); if (result.isError) { if (!mounted) return; - if (result.error == ErrorCode.UsernameAlreadyTaken) { + if (result.error == ErrorCode.UsernameAlreadyTaken || + result.error == ErrorCode.UsernameNotValid) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( - content: Text(context.lang.errorUsernameAlreadyTaken), + content: Text( + result.error == ErrorCode.UsernameAlreadyTaken + ? context.lang.errorUsernameAlreadyTaken + : context.lang.errorUsernameNotValid, + ), duration: const Duration(seconds: 3), ), );