From 49b77d630affc74f0e42ad430265f3618fb34805 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 4 Feb 2022 15:03:13 +0100 Subject: [PATCH] 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. --- user.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/user.go b/user.go index 0ed789c..777eb27 100644 --- a/user.go +++ b/user.go @@ -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() }