Empty channels were only cleaned up on PART, not QUIT.
This commit is contained in:
Shivaram Lingamneni 2018-03-01 10:37:30 -05:00
parent 898fb41485
commit ef99bc48d1
2 changed files with 14 additions and 4 deletions

View File

@ -748,10 +748,15 @@ func (channel *Channel) applyModeMask(client *Client, mode modes.Mode, op modes.
func (channel *Channel) Quit(client *Client) {
channel.stateMutex.Lock()
channel.members.Remove(client)
empty := len(channel.members) == 0
channel.stateMutex.Unlock()
channel.regenerateMembersCache(false)
client.removeChannel(channel)
if empty {
client.server.channels.Cleanup(channel)
}
}
func (channel *Channel) Kick(client *Client, target *Client, comment string, rb *ResponseBuffer) {

View File

@ -76,18 +76,20 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, rb *Resp
entry.channel.Join(client, key, rb)
cm.maybeCleanup(entry, true)
cm.maybeCleanup(entry.channel, true)
return nil
}
func (cm *ChannelManager) maybeCleanup(entry *channelManagerEntry, afterJoin bool) {
func (cm *ChannelManager) maybeCleanup(channel *Channel, afterJoin bool) {
cm.Lock()
defer cm.Unlock()
if entry.channel == nil {
entry := cm.chans[channel.NameCasefolded()]
if entry == nil || entry.channel != channel {
return
}
if afterJoin {
entry.pendingJoins -= 1
}
@ -121,10 +123,13 @@ func (cm *ChannelManager) Part(client *Client, name string, message string, rb *
return errNoSuchChannel
}
entry.channel.Part(client, message, rb)
cm.maybeCleanup(entry, false)
return nil
}
func (cm *ChannelManager) Cleanup(channel *Channel) {
cm.maybeCleanup(channel, false)
}
// Rename renames a channel (but does not notify the members)
func (cm *ChannelManager) Rename(name string, newname string) error {
cfname, err := CasefoldChannel(name)