summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannik <jannik@outlook.com>2022-01-10 09:59:20 +0100
committerJannik <jannik@outlook.com>2022-01-10 09:59:20 +0100
commit0aa5ad31d0fac66584d12e230bf69d988f2d9208 (patch)
treed00f0895122bbbe950063e2c4d79afa1a4e8dcba
parentdbb878833b5df58c071637d5732e556f0e2b04a7 (diff)
:children_crossing: add minimum of 10 suggested usernames until custom pool is usedfeat/jv/custom-username-suggestions
-rw-r--r--core/data/config.go1
-rw-r--r--core/user/user.go3
2 files changed, 3 insertions, 1 deletions
diff --git a/core/data/config.go b/core/data/config.go
index c25db0df8..0eaa0f57d 100644
--- a/core/data/config.go
+++ b/core/data/config.go
@@ -604,6 +604,7 @@ func SetForbiddenUsernameList(usernames []string) error {
}
// GetSuggestedUsernamesList will return the suggested usernames as a comma separated string.
+// If the number of suggested usernames is smaller than 10, the number pool is not used (see code in the CreateAnonymousUser function).
func GetSuggestedUsernamesList() []string {
usernameString, err := _datastore.GetString(suggestedUsernamesKey)
diff --git a/core/user/user.go b/core/user/user.go
index 3159d340a..218cb3d18 100644
--- a/core/user/user.go
+++ b/core/user/user.go
@@ -17,6 +17,7 @@ import (
var _datastore *data.Datastore
const moderatorScopeKey = "MODERATOR"
+const minSuggestedUsernamePoolLength = 10
// User represents a single chat user.
type User struct {
@@ -59,7 +60,7 @@ func CreateAnonymousUser(displayName string) (*User, error) {
if displayName == "" {
suggestedUsernamesList := data.GetSuggestedUsernamesList()
- if len(suggestedUsernamesList) != 0 {
+ if len(suggestedUsernamesList) >= minSuggestedUsernamePoolLength {
index := utils.RandomIndex(len(suggestedUsernamesList))
displayName = suggestedUsernamesList[index]
} else {