Drop user.forEachNetwork
It's a trivial for loop.
This commit is contained in:
parent
f2a03cf7a1
commit
0b5da29916
@ -351,7 +351,9 @@ func (dc *downstreamConn) forEachNetwork(f func(*network)) {
|
|||||||
if dc.network != nil {
|
if dc.network != nil {
|
||||||
f(dc.network)
|
f(dc.network)
|
||||||
} else if dc.isMultiUpstream {
|
} else if dc.isMultiUpstream {
|
||||||
dc.user.forEachNetwork(f)
|
for _, network := range dc.user.networks {
|
||||||
|
f(network)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,11 +777,12 @@ func (dc *downstreamConn) handleMessageUnregistered(ctx context.Context, msg *ir
|
|||||||
}
|
}
|
||||||
|
|
||||||
var match *network
|
var match *network
|
||||||
dc.user.forEachNetwork(func(net *network) {
|
for _, net := range dc.user.networks {
|
||||||
if net.ID == id {
|
if net.ID == id {
|
||||||
match = net
|
match = net
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
if match == nil {
|
if match == nil {
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: "FAIL",
|
Command: "FAIL",
|
||||||
@ -1436,7 +1439,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error {
|
|||||||
|
|
||||||
if dc.caps["soju.im/bouncer-networks-notify"] {
|
if dc.caps["soju.im/bouncer-networks-notify"] {
|
||||||
dc.SendBatch("soju.im/bouncer-networks", nil, nil, func(batchRef irc.TagValue) {
|
dc.SendBatch("soju.im/bouncer-networks", nil, nil, func(batchRef irc.TagValue) {
|
||||||
dc.user.forEachNetwork(func(network *network) {
|
for _, network := range dc.user.networks {
|
||||||
idStr := fmt.Sprintf("%v", network.ID)
|
idStr := fmt.Sprintf("%v", network.ID)
|
||||||
attrs := getNetworkAttrs(network)
|
attrs := getNetworkAttrs(network)
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
@ -1445,7 +1448,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error {
|
|||||||
Command: "BOUNCER",
|
Command: "BOUNCER",
|
||||||
Params: []string{"NETWORK", idStr, attrs.String()},
|
Params: []string{"NETWORK", idStr, attrs.String()},
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2748,7 +2751,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
}}
|
}}
|
||||||
case "LISTNETWORKS":
|
case "LISTNETWORKS":
|
||||||
dc.SendBatch("soju.im/bouncer-networks", nil, nil, func(batchRef irc.TagValue) {
|
dc.SendBatch("soju.im/bouncer-networks", nil, nil, func(batchRef irc.TagValue) {
|
||||||
dc.user.forEachNetwork(func(network *network) {
|
for _, network := range dc.user.networks {
|
||||||
idStr := fmt.Sprintf("%v", network.ID)
|
idStr := fmt.Sprintf("%v", network.ID)
|
||||||
attrs := getNetworkAttrs(network)
|
attrs := getNetworkAttrs(network)
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
@ -2757,7 +2760,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
Command: "BOUNCER",
|
Command: "BOUNCER",
|
||||||
Params: []string{"NETWORK", idStr, attrs.String()},
|
Params: []string{"NETWORK", idStr, attrs.String()},
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
case "ADDNETWORK":
|
case "ADDNETWORK":
|
||||||
var attrsStr string
|
var attrsStr string
|
||||||
|
@ -506,7 +506,7 @@ func handleServiceNetworkCreate(ctx context.Context, dc *downstreamConn, params
|
|||||||
|
|
||||||
func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params []string) error {
|
func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params []string) error {
|
||||||
n := 0
|
n := 0
|
||||||
dc.user.forEachNetwork(func(net *network) {
|
for _, net := range dc.user.networks {
|
||||||
var statuses []string
|
var statuses []string
|
||||||
var details string
|
var details string
|
||||||
if uc := net.conn; uc != nil {
|
if uc := net.conn; uc != nil {
|
||||||
@ -541,7 +541,7 @@ func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params
|
|||||||
sendServicePRIVMSG(dc, s)
|
sendServicePRIVMSG(dc, s)
|
||||||
|
|
||||||
n++
|
n++
|
||||||
})
|
}
|
||||||
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
sendServicePRIVMSG(dc, `No network configured, add one with "network create".`)
|
sendServicePRIVMSG(dc, `No network configured, add one with "network create".`)
|
||||||
@ -969,7 +969,9 @@ func handleServiceChannelStatus(ctx context.Context, dc *downstreamConn, params
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *networkName == "" {
|
if *networkName == "" {
|
||||||
dc.user.forEachNetwork(sendNetwork)
|
for _, net := range dc.user.networks {
|
||||||
|
sendNetwork(net)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
net := dc.user.getNetwork(*networkName)
|
net := dc.user.getNetwork(*networkName)
|
||||||
if net == nil {
|
if net == nil {
|
||||||
|
10
user.go
10
user.go
@ -464,12 +464,6 @@ func newUser(srv *Server, record *User) *user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *user) forEachNetwork(f func(*network)) {
|
|
||||||
for _, network := range u.networks {
|
|
||||||
f(network)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
||||||
for _, network := range u.networks {
|
for _, network := range u.networks {
|
||||||
if network.conn == nil {
|
if network.conn == nil {
|
||||||
@ -992,11 +986,11 @@ func (u *user) updateUser(ctx context.Context, record *User) error {
|
|||||||
if realnameUpdated {
|
if realnameUpdated {
|
||||||
// Re-connect to networks which use the default realname
|
// Re-connect to networks which use the default realname
|
||||||
var needUpdate []Network
|
var needUpdate []Network
|
||||||
u.forEachNetwork(func(net *network) {
|
for _, net := range u.networks {
|
||||||
if net.Realname == "" {
|
if net.Realname == "" {
|
||||||
needUpdate = append(needUpdate, net.Network)
|
needUpdate = append(needUpdate, net.Network)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
var netErr error
|
var netErr error
|
||||||
for _, net := range needUpdate {
|
for _, net := range needUpdate {
|
||||||
|
Loading…
Reference in New Issue
Block a user