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.
This commit is contained in:
Simon Ser 2022-02-04 15:03:13 +01:00
parent 0b5da29916
commit 49b77d630a

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()
}