mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
GODT-2008: Ensure user's addresses are returned in sorted order
This commit is contained in:
@ -201,10 +201,14 @@ func run(c *cli.Context) error { //nolint:funlen
|
||||
func withSingleInstance(locations *locations.Locations, version *semver.Version, fn func() error) error {
|
||||
lock, err := checkSingleInstance(locations.GetLockFile(), version)
|
||||
if err != nil {
|
||||
logrus.Info("Another instance is already running; raising it")
|
||||
|
||||
if ok := focus.TryRaise(); !ok {
|
||||
return fmt.Errorf("another instance is already running but it could not be raised")
|
||||
}
|
||||
|
||||
logrus.Info("The other instance has been raised")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -264,10 +265,17 @@ func (user *User) Match(query string) bool {
|
||||
}, user.apiUserLock, user.apiAddrsLock)
|
||||
}
|
||||
|
||||
// Emails returns all the user's email addresses via the callback.
|
||||
// Emails returns all the user's email addresses.
|
||||
// It returns them in sorted order; the user's primary address is first.
|
||||
func (user *User) Emails() []string {
|
||||
return safe.RLockRet(func() []string {
|
||||
return xslices.Map(maps.Values(user.apiAddrs), func(addr liteapi.Address) string {
|
||||
addresses := maps.Values(user.apiAddrs)
|
||||
|
||||
slices.SortFunc(addresses, func(a, b liteapi.Address) bool {
|
||||
return a.Order < b.Order
|
||||
})
|
||||
|
||||
return xslices.Map(addresses, func(addr liteapi.Address) string {
|
||||
return addr.Email
|
||||
})
|
||||
}, user.apiAddrsLock)
|
||||
|
||||
Reference in New Issue
Block a user