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:
parent
0b5da29916
commit
49b77d630a
10
user.go
10
user.go
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/irc.v3"
|
"gopkg.in/irc.v3"
|
||||||
@ -516,6 +517,10 @@ func (u *user) run() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(networks, func(i, j int) bool {
|
||||||
|
return networks[i].ID < networks[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
for _, record := range networks {
|
for _, record := range networks {
|
||||||
record := record
|
record := record
|
||||||
channels, err := u.srv.db.ListChannels(context.TODO(), record.ID)
|
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) {
|
func (u *user) addNetwork(network *network) {
|
||||||
u.networks = append(u.networks, 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()
|
go network.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user