From 9cf42df1eabe458221b467f2199967bbf4bbaf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Fri, 1 May 2020 05:40:49 +0200 Subject: [PATCH] Remove channel from reconnect list when parting --- pkg/irc/client.go | 13 +++++++++++++ pkg/irc/client_test.go | 2 ++ 2 files changed, 15 insertions(+) diff --git a/pkg/irc/client.go b/pkg/irc/client.go index ecb1a292..7e73d051 100644 --- a/pkg/irc/client.go +++ b/pkg/irc/client.go @@ -119,6 +119,7 @@ func (c *Client) Join(channels ...string) { func (c *Client) Part(channels ...string) { c.Write("PART " + strings.Join(channels, ",")) + c.removeChannels(channels...) } func (c *Client) Topic(channel string, topic ...string) { @@ -183,6 +184,18 @@ func (c *Client) addChannel(channel string) { 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() { c.lock.Lock() if len(c.channels) > 0 { diff --git a/pkg/irc/client_test.go b/pkg/irc/client_test.go index 5a025db4..3e724656 100644 --- a/pkg/irc/client_test.go +++ b/pkg/irc/client_test.go @@ -162,6 +162,8 @@ func TestFlushChannels(t *testing.T) { c.flushChannels() assert.Equal(t, <-out, "JOIN #chan1\r\n") c.addChannel("#chan2") + c.addChannel("#chan4") + c.removeChannels("#chan4") c.addChannel("#chan3") c.flushChannels() assert.Equal(t, <-out, "JOIN #chan2,#chan3\r\n")