3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

Merge pull request #1758 from ergochat/channel_creation

fix channel creation bugs
This commit is contained in:
Shivaram Lingamneni 2021-07-15 08:35:29 -04:00 committed by GitHub
commit ad61f9f213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,23 +117,25 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin
return errNoSuchChannel, "" return errNoSuchChannel, ""
} }
channel, err := func() (*Channel, error) { channel, err, newChannel := func() (*Channel, error, bool) {
var newChannel bool
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
if cm.purgedChannels.Has(casefoldedName) { if cm.purgedChannels.Has(casefoldedName) {
return nil, errChannelPurged return nil, errChannelPurged, false
} }
entry := cm.chans[casefoldedName] entry := cm.chans[casefoldedName]
if entry == nil { if entry == nil {
registered := cm.registeredChannels.Has(casefoldedName) registered := cm.registeredChannels.Has(casefoldedName)
// enforce OpOnlyCreation // enforce OpOnlyCreation
if !registered && server.Config().Channels.OpOnlyCreation && !client.HasRoleCapabs("chanreg") { if !registered && server.Config().Channels.OpOnlyCreation &&
return nil, errInsufficientPrivs !(isSajoin || client.HasRoleCapabs("chanreg")) {
return nil, errInsufficientPrivs, false
} }
// enforce confusables // enforce confusables
if !registered && (cm.chansSkeletons.Has(skeleton) || cm.registeredSkeletons.Has(skeleton)) { if !registered && (cm.chansSkeletons.Has(skeleton) || cm.registeredSkeletons.Has(skeleton)) {
return nil, errConfusableIdentifier return nil, errConfusableIdentifier, false
} }
entry = &channelManagerEntry{ entry = &channelManagerEntry{
channel: NewChannel(server, name, casefoldedName, registered), channel: NewChannel(server, name, casefoldedName, registered),
@ -148,9 +150,10 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin
entry.skeleton = skeleton entry.skeleton = skeleton
} }
cm.chans[casefoldedName] = entry cm.chans[casefoldedName] = entry
newChannel = true
} }
entry.pendingJoins += 1 entry.pendingJoins += 1
return entry.channel, nil return entry.channel, nil, newChannel
}() }()
if err != nil { if err != nil {
@ -158,7 +161,7 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin
} }
channel.EnsureLoaded() channel.EnsureLoaded()
err, forward = channel.Join(client, key, isSajoin, rb) err, forward = channel.Join(client, key, isSajoin || newChannel, rb)
cm.maybeCleanup(channel, true) cm.maybeCleanup(channel, true)