Don't provide name in channel casemapMap Set and ForEach

The name is already provided in the struct.
This commit is contained in:
Simon Ser 2022-06-06 10:04:50 +02:00
parent 657e25b25c
commit 09f2cf8489
5 changed files with 21 additions and 21 deletions

View File

@ -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)

16
irc.go
View File

@ -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))
}
}

View File

@ -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)
})

View File

@ -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)

View File

@ -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)
})