From 0b5da299162fcd4c6a10b425a1cd54d8faf108c1 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 4 Feb 2022 14:01:27 +0100 Subject: [PATCH] Drop user.forEachNetwork It's a trivial for loop. --- downstream.go | 17 ++++++++++------- service.go | 8 +++++--- user.go | 10 ++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/downstream.go b/downstream.go index ad4c352..a52b1ad 100644 --- a/downstream.go +++ b/downstream.go @@ -351,7 +351,9 @@ func (dc *downstreamConn) forEachNetwork(f func(*network)) { if dc.network != nil { f(dc.network) } 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 - dc.user.forEachNetwork(func(net *network) { + for _, net := range dc.user.networks { if net.ID == id { match = net + break } - }) + } if match == nil { return ircError{&irc.Message{ Command: "FAIL", @@ -1436,7 +1439,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error { if dc.caps["soju.im/bouncer-networks-notify"] { 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) attrs := getNetworkAttrs(network) dc.SendMessage(&irc.Message{ @@ -1445,7 +1448,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error { Command: "BOUNCER", Params: []string{"NETWORK", idStr, attrs.String()}, }) - }) + } }) } @@ -2748,7 +2751,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. }} case "LISTNETWORKS": 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) attrs := getNetworkAttrs(network) dc.SendMessage(&irc.Message{ @@ -2757,7 +2760,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Command: "BOUNCER", Params: []string{"NETWORK", idStr, attrs.String()}, }) - }) + } }) case "ADDNETWORK": var attrsStr string diff --git a/service.go b/service.go index 80fb261..f548535 100644 --- a/service.go +++ b/service.go @@ -506,7 +506,7 @@ func handleServiceNetworkCreate(ctx context.Context, dc *downstreamConn, params func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params []string) error { n := 0 - dc.user.forEachNetwork(func(net *network) { + for _, net := range dc.user.networks { var statuses []string var details string if uc := net.conn; uc != nil { @@ -541,7 +541,7 @@ func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params sendServicePRIVMSG(dc, s) n++ - }) + } if n == 0 { sendServicePRIVMSG(dc, `No network configured, add one with "network create".`) @@ -969,7 +969,9 @@ func handleServiceChannelStatus(ctx context.Context, dc *downstreamConn, params } if *networkName == "" { - dc.user.forEachNetwork(sendNetwork) + for _, net := range dc.user.networks { + sendNetwork(net) + } } else { net := dc.user.getNetwork(*networkName) if net == nil { diff --git a/user.go b/user.go index 78c638c..0ed789c 100644 --- a/user.go +++ b/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)) { for _, network := range u.networks { if network.conn == nil { @@ -992,11 +986,11 @@ func (u *user) updateUser(ctx context.Context, record *User) error { if realnameUpdated { // Re-connect to networks which use the default realname var needUpdate []Network - u.forEachNetwork(func(net *network) { + for _, net := range u.networks { if net.Realname == "" { needUpdate = append(needUpdate, net.Network) } - }) + } var netErr error for _, net := range needUpdate {