feat: add custom username suggestions pool (#1644)

*  add custom username suggestions pool

* 🚸 add minimum of 10 suggested usernames until custom pool is used
This commit is contained in:
Jannik
2022-01-12 19:18:08 +01:00
committed by GitHub
parent 814c65eeb7
commit d3cfc40b5c
6 changed files with 71 additions and 11 deletions

View File

@@ -42,6 +42,7 @@ const externalActionsKey = "external_actions"
const customStylesKey = "custom_styles"
const videoCodecKey = "video_codec"
const blockedUsernamesKey = "blocked_usernames"
const suggestedUsernamesKey = "suggested_usernames"
// GetExtraPageBodyContent will return the user-supplied body content.
func GetExtraPageBodyContent() string {
@@ -601,3 +602,23 @@ func SetForbiddenUsernameList(usernames []string) error {
usernameListString := strings.Join(usernames, ",")
return _datastore.SetString(blockedUsernamesKey, usernameListString)
}
// 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)
if err != nil || usernameString == "" {
return []string{}
}
suggestionList := strings.Split(usernameString, ",")
return suggestionList
}
// SetSuggestedUsernamesList sets the username suggestion list as a comma separated string.
func SetSuggestedUsernamesList(usernames []string) error {
usernameListString := strings.Join(usernames, ",")
return _datastore.SetString(suggestedUsernamesKey, usernameListString)
}