Remove channel from reconnect list when parting

This commit is contained in:
Ken-Håvard Lieng 2020-05-01 05:40:49 +02:00
parent b81e1e482a
commit 9cf42df1ea
2 changed files with 15 additions and 0 deletions

View File

@ -119,6 +119,7 @@ func (c *Client) Join(channels ...string) {
func (c *Client) Part(channels ...string) { func (c *Client) Part(channels ...string) {
c.Write("PART " + strings.Join(channels, ",")) c.Write("PART " + strings.Join(channels, ","))
c.removeChannels(channels...)
} }
func (c *Client) Topic(channel string, topic ...string) { func (c *Client) Topic(channel string, topic ...string) {
@ -183,6 +184,18 @@ func (c *Client) addChannel(channel string) {
c.lock.Unlock() c.lock.Unlock()
} }
func (c *Client) removeChannels(channels ...string) {
c.lock.Lock()
for _, removeCh := range channels {
for i, ch := range c.channels {
if c.EqualFold(removeCh, ch) {
c.channels = append(c.channels[:i], c.channels[i+1:]...)
}
}
}
c.lock.Unlock()
}
func (c *Client) flushChannels() { func (c *Client) flushChannels() {
c.lock.Lock() c.lock.Lock()
if len(c.channels) > 0 { if len(c.channels) > 0 {

View File

@ -162,6 +162,8 @@ func TestFlushChannels(t *testing.T) {
c.flushChannels() c.flushChannels()
assert.Equal(t, <-out, "JOIN #chan1\r\n") assert.Equal(t, <-out, "JOIN #chan1\r\n")
c.addChannel("#chan2") c.addChannel("#chan2")
c.addChannel("#chan4")
c.removeChannels("#chan4")
c.addChannel("#chan3") c.addChannel("#chan3")
c.flushChannels() c.flushChannels()
assert.Equal(t, <-out, "JOIN #chan2,#chan3\r\n") assert.Equal(t, <-out, "JOIN #chan2,#chan3\r\n")