mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
Read account names and additional nicknames from the db to avoid casefolding issues.
This commit is contained in:
parent
6019ed1e29
commit
73bea0168d
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -1047,15 +1048,37 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
|
||||
return err
|
||||
}
|
||||
|
||||
func (am *AccountManager) AllNicks() []string {
|
||||
am.RLock()
|
||||
defer am.RUnlock()
|
||||
// AllNicks returns the uncasefolded nicknames for all accounts, including additional (grouped) nicks.
|
||||
func (am *AccountManager) AllNicks() (result []string) {
|
||||
// Account names
|
||||
accountNamePrefix := fmt.Sprintf(keyAccountName, "")
|
||||
am.server.store.View(func(tx *buntdb.Tx) error {
|
||||
return tx.AscendGreaterOrEqual("", accountNamePrefix, func(key, value string) bool {
|
||||
if !strings.HasPrefix(key, accountNamePrefix) {
|
||||
return false
|
||||
}
|
||||
result = append(result, value)
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
nicks := make([]string, 0, len(am.nickToAccount))
|
||||
for nick := range am.nickToAccount {
|
||||
nicks = append(nicks, nick)
|
||||
}
|
||||
return nicks
|
||||
// Additional nicknames
|
||||
accountAdditionalNicksPrefix := fmt.Sprintf(keyAccountAdditionalNicks, "")
|
||||
am.server.store.View(func(tx *buntdb.Tx) error {
|
||||
return tx.AscendGreaterOrEqual("", accountAdditionalNicksPrefix, func(key, value string) bool {
|
||||
if !strings.HasPrefix(key, accountAdditionalNicksPrefix) {
|
||||
return false
|
||||
}
|
||||
additionalNicks := unmarshalReservedNicks(value)
|
||||
for _, additionalNick := range additionalNicks {
|
||||
result = append(result, additionalNick)
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
sort.Strings(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user