Remove channel from reconnect list when parting
This commit is contained in:
parent
b81e1e482a
commit
9cf42df1ea
@ -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 {
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user