summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 {