From 696980367dd5e07bad1006fed4f4703520d1c17c Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 29 Jun 2020 15:41:29 -0400 Subject: [PATCH] fix #1161 --- irc/channel.go | 7 +++++++ irc/handlers.go | 11 +++++++++-- irc/server.go | 20 -------------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 99e1960c..f1057e1f 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -1460,3 +1460,10 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, invitee.AwayMessage()) } } + +// data for RPL_LIST +func (channel *Channel) listData() (memberCount int, name, topic string) { + channel.stateMutex.RLock() + defer channel.stateMutex.RUnlock() + return len(channel.members), channel.name, channel.topic +} diff --git a/irc/handlers.go b/irc/handlers.go index 64b271f6..fc8d0d3d 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -1530,6 +1530,13 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp } } + nick := client.Nick() + rplList := func(channel *Channel) { + if members, name, topic := channel.listData(); members != 0 { + rb.Add(nil, client.server.name, RPL_LIST, nick, name, strconv.Itoa(members), topic) + } + } + clientIsOp := client.HasMode(modes.Operator) if len(channels) == 0 { for _, channel := range server.channels.Channels() { @@ -1537,7 +1544,7 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp continue } if matcher.Matches(channel) { - client.RplList(channel, rb) + rplList(channel) } } } else { @@ -1555,7 +1562,7 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp continue } if matcher.Matches(channel) { - client.RplList(channel, rb) + rplList(channel) } } } diff --git a/irc/server.go b/irc/server.go index 98725553..577959e1 100644 --- a/irc/server.go +++ b/irc/server.go @@ -967,26 +967,6 @@ func (matcher *elistMatcher) Matches(channel *Channel) bool { return true } -// RplList returns the RPL_LIST numeric for the given channel. -func (target *Client) RplList(channel *Channel, rb *ResponseBuffer) { - // get the correct number of channel members - var memberCount int - if target.HasMode(modes.Operator) || channel.hasClient(target) { - memberCount = len(channel.Members()) - } else { - for _, member := range channel.Members() { - if !member.HasMode(modes.Invisible) { - memberCount++ - } - } - } - - // #704: some channels are kept around even with no members - if memberCount != 0 { - rb.Add(nil, target.server.name, RPL_LIST, target.nick, channel.name, strconv.Itoa(memberCount), channel.topic) - } -} - var ( infoString1 = strings.Split(` ▄▄▄ ▄▄▄· ▄▄ • ▐ ▄ ▪ ▀▄ █·▐█ ▀█ ▐█ ▀ ▪▪ •█▌▐█▪