GODT-2008: Ensure user's addresses are returned in sorted order

This commit is contained in:
James Houlahan
2022-11-01 12:54:38 +01:00
parent a213b48f93
commit dbfb7572a8
2 changed files with 14 additions and 2 deletions

View File

@ -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
}

View File

@ -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)