Ensure consistent network ordering

Right now there is no consistent ordering in the network list:
no ORDER BY in the DB, and network updates move entries to the end.

Let's always sort by network ID so that users don't see the entries
move around.

I've contemplated sorting by Network.GetName() instead, but:

- Clients have now way to figure out dynamic order changes, e.g.
  when renaming a network.
- Some clients might use ISUPPORT NETWORK when a user hasn't
  explicitly named a network, but soju won't use that for ordering,
  leading to non-alphabetic ordering in the client.

Let's leave it to clients to sort the networks by display name if
they want to.

git-svn-id: file:///srv/svn/repo/suika/trunk@769 f0ae65fe-ee39-954e-97ec-027ff2717ef4
This commit is contained in:
contact 2022-02-04 14:03:13 +00:00
parent 6cbc9f985a
commit 259caf4a78

10
user.go
View File

@ -8,6 +8,7 @@ import (
"fmt"
"math/big"
"net"
"sort"
"time"
"gopkg.in/irc.v3"
@ -516,6 +517,10 @@ func (u *user) run() {
return
}
sort.Slice(networks, func(i, j int) bool {
return networks[i].ID < networks[j].ID
})
for _, record := range networks {
record := record
channels, err := u.srv.db.ListChannels(context.TODO(), record.ID)
@ -765,6 +770,11 @@ func (u *user) handleUpstreamDisconnected(uc *upstreamConn) {
func (u *user) addNetwork(network *network) {
u.networks = append(u.networks, network)
sort.Slice(u.networks, func(i, j int) bool {
return u.networks[i].ID < u.networks[j].ID
})
go network.run()
}