sorting nicks on /names and /list

This commit is contained in:
Lucas Hourahine 2020-07-16 13:25:14 -04:00
parent 3c4d90cfc1
commit 09c8bbdd4c

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"time" "time"
"sort"
"github.com/shazow/ssh-chat/chat/message" "github.com/shazow/ssh-chat/chat/message"
"github.com/shazow/ssh-chat/internal/sanitize" "github.com/shazow/ssh-chat/internal/sanitize"
@ -189,6 +190,7 @@ func InitCommands(c *Commands) {
} }
names := room.Members.ListPrefix("") names := room.Members.ListPrefix("")
sort.Slice(names, func(i, j int) bool { return names[i].Key() < names[j].Key() })
colNames := make([]string, len(names)) colNames := make([]string, len(names))
for i, uname := range names { for i, uname := range names {
colNames[i] = colorize(uname.Value().(*Member).User) colNames[i] = colorize(uname.Value().(*Member).User)