From 09f2cf8489de35ce249215c06c776465e66c2fc1 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Jun 2022 10:04:50 +0200 Subject: [PATCH] Don't provide name in channel casemapMap Set and ForEach The name is already provided in the struct. --- downstream.go | 8 ++++---- irc.go | 16 ++++++++-------- service.go | 2 +- upstream.go | 8 ++++---- user.go | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/downstream.go b/downstream.go index bed7616..575c7a2 100644 --- a/downstream.go +++ b/downstream.go @@ -1592,7 +1592,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error { } dc.forEachUpstream(func(uc *upstreamConn) { - uc.channels.ForEach(func(_ string, ch *upstreamChannel) { + uc.channels.ForEach(func(ch *upstreamChannel) { if !ch.complete { return } @@ -1950,7 +1950,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Name: upstreamName, Key: key, } - uc.network.channels.Set(upstreamName, ch) + uc.network.channels.Set(ch) } if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil { dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err) @@ -1979,10 +1979,10 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. uc.network.detach(ch) } else { ch = &database.Channel{ - Name: name, + Name: upstreamName, Detached: true, } - uc.network.channels.Set(upstreamName, ch) + uc.network.channels.Set(ch) } if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil { dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err) diff --git a/irc.go b/irc.go index 9fd6b76..a75b914 100644 --- a/irc.go +++ b/irc.go @@ -374,13 +374,13 @@ func (cm *upstreamChannelCasemapMap) Get(name string) *upstreamChannel { } } -func (cm *upstreamChannelCasemapMap) Set(name string, uch *upstreamChannel) { - cm.set(name, uch) +func (cm *upstreamChannelCasemapMap) Set(uch *upstreamChannel) { + cm.set(uch.Name, uch) } -func (cm *upstreamChannelCasemapMap) ForEach(f func(string, *upstreamChannel)) { +func (cm *upstreamChannelCasemapMap) ForEach(f func(*upstreamChannel)) { for _, entry := range cm.m { - f(entry.originalKey, entry.value.(*upstreamChannel)) + f(entry.value.(*upstreamChannel)) } } @@ -394,13 +394,13 @@ func (cm *channelCasemapMap) Get(name string) *database.Channel { } } -func (cm *channelCasemapMap) Set(name string, ch *database.Channel) { - cm.set(name, ch) +func (cm *channelCasemapMap) Set(ch *database.Channel) { + cm.set(ch.Name, ch) } -func (cm *channelCasemapMap) ForEach(f func(string, *database.Channel)) { +func (cm *channelCasemapMap) ForEach(f func(*database.Channel)) { for _, entry := range cm.m { - f(entry.originalKey, entry.value.(*database.Channel)) + f(entry.value.(*database.Channel)) } } diff --git a/service.go b/service.go index d1c944c..4acf94d 100644 --- a/service.go +++ b/service.go @@ -974,7 +974,7 @@ func handleServiceChannelStatus(ctx context.Context, dc *downstreamConn, params sendNetwork := func(net *network) { var channels []*database.Channel - net.channels.ForEach(func(_ string, ch *database.Channel) { + net.channels.ForEach(func(ch *database.Channel) { channels = append(channels, ch) }) diff --git a/upstream.go b/upstream.go index c708bc5..2b06acd 100644 --- a/upstream.go +++ b/upstream.go @@ -757,7 +757,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err if uc.network.channels.Len() > 0 { var channels, keys []string - uc.network.channels.ForEach(func(_ string, ch *database.Channel) { + uc.network.channels.ForEach(func(ch *database.Channel) { channels = append(channels, ch.Name) keys = append(keys, ch.Key) }) @@ -917,7 +917,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err uc.nickCM = uc.network.casemap(uc.nick) } - uc.channels.ForEach(func(_ string, ch *upstreamChannel) { + uc.channels.ForEach(func(ch *upstreamChannel) { memberships := ch.Members.Get(msg.Prefix.Name) if memberships != nil { ch.Members.Del(msg.Prefix.Name) @@ -993,7 +993,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err uc.logger.Printf("joined channel %q", ch) members := membershipsCasemapMap{newCasemapMap()} members.casemap = uc.network.casemap - uc.channels.Set(ch, &upstreamChannel{ + uc.channels.Set(&upstreamChannel{ Name: ch, conn: uc, Members: members, @@ -1064,7 +1064,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err uc.logger.Printf("quit") } - uc.channels.ForEach(func(_ string, ch *upstreamChannel) { + uc.channels.ForEach(func(ch *upstreamChannel) { if ch.Members.Has(msg.Prefix.Name) { ch.Members.Del(msg.Prefix.Name) uc.appendLog(ch.Name, msg) diff --git a/user.go b/user.go index cac5312..36b6200 100644 --- a/user.go +++ b/user.go @@ -143,7 +143,7 @@ func newNetwork(user *user, record *database.Network, channels []database.Channe m := channelCasemapMap{newCasemapMap()} for _, ch := range channels { ch := ch - m.Set(ch.Name, &ch) + m.Set(&ch) } return &network{ @@ -374,7 +374,7 @@ func (net *network) updateCasemapping(newCasemap casemapping) { net.delivered.m.SetCasemapping(newCasemap) if uc := net.conn; uc != nil { uc.channels.SetCasemapping(newCasemap) - uc.channels.ForEach(func(_ string, uch *upstreamChannel) { + uc.channels.ForEach(func(uch *upstreamChannel) { uch.Members.SetCasemapping(newCasemap) }) uc.monitored.SetCasemapping(newCasemap) @@ -744,7 +744,7 @@ func (u *user) handleUpstreamDisconnected(uc *upstreamConn) { uc.abortPendingCommands() - uc.channels.ForEach(func(_ string, uch *upstreamChannel) { + uc.channels.ForEach(func(uch *upstreamChannel) { uch.updateAutoDetach(0) }) @@ -921,7 +921,7 @@ func (u *user) updateNetwork(ctx context.Context, record *database.Network) (*ne // Most network changes require us to re-connect to the upstream server channels := make([]database.Channel, 0, network.channels.Len()) - network.channels.ForEach(func(_ string, ch *database.Channel) { + network.channels.ForEach(func(ch *database.Channel) { channels = append(channels, *ch) })