mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 05:49:25 +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"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -1047,15 +1048,37 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *AccountManager) AllNicks() []string {
|
// AllNicks returns the uncasefolded nicknames for all accounts, including additional (grouped) nicks.
|
||||||
am.RLock()
|
func (am *AccountManager) AllNicks() (result []string) {
|
||||||
defer am.RUnlock()
|
// 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))
|
// Additional nicknames
|
||||||
for nick := range am.nickToAccount {
|
accountAdditionalNicksPrefix := fmt.Sprintf(keyAccountAdditionalNicks, "")
|
||||||
nicks = append(nicks, nick)
|
am.server.store.View(func(tx *buntdb.Tx) error {
|
||||||
}
|
return tx.AscendGreaterOrEqual("", accountAdditionalNicksPrefix, func(key, value string) bool {
|
||||||
return nicks
|
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) {
|
func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user