3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

Merge pull request #205 from slingamn/issue204

fix #204
This commit is contained in:
Daniel Oaks 2018-03-01 10:07:32 -08:00 committed by GitHub
commit b211fd35da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)