3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00
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) { func (channel *Channel) Quit(client *Client) {
channel.stateMutex.Lock() channel.stateMutex.Lock()
channel.members.Remove(client) channel.members.Remove(client)
empty := len(channel.members) == 0
channel.stateMutex.Unlock() channel.stateMutex.Unlock()
channel.regenerateMembersCache(false) channel.regenerateMembersCache(false)
client.removeChannel(channel) client.removeChannel(channel)
if empty {
client.server.channels.Cleanup(channel)
}
} }
func (channel *Channel) Kick(client *Client, target *Client, comment string, rb *ResponseBuffer) { 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) entry.channel.Join(client, key, rb)
cm.maybeCleanup(entry, true) cm.maybeCleanup(entry.channel, true)
return nil return nil
} }
func (cm *ChannelManager) maybeCleanup(entry *channelManagerEntry, afterJoin bool) { func (cm *ChannelManager) maybeCleanup(channel *Channel, afterJoin bool) {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
if entry.channel == nil { entry := cm.chans[channel.NameCasefolded()]
if entry == nil || entry.channel != channel {
return return
} }
if afterJoin { if afterJoin {
entry.pendingJoins -= 1 entry.pendingJoins -= 1
} }
@ -121,10 +123,13 @@ func (cm *ChannelManager) Part(client *Client, name string, message string, rb *
return errNoSuchChannel return errNoSuchChannel
} }
entry.channel.Part(client, message, rb) entry.channel.Part(client, message, rb)
cm.maybeCleanup(entry, false)
return nil return nil
} }
func (cm *ChannelManager) Cleanup(channel *Channel) {
cm.maybeCleanup(channel, false)
}
// Rename renames a channel (but does not notify the members) // Rename renames a channel (but does not notify the members)
func (cm *ChannelManager) Rename(name string, newname string) error { func (cm *ChannelManager) Rename(name string, newname string) error {
cfname, err := CasefoldChannel(name) cfname, err := CasefoldChannel(name)