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 a0477e6c..bd254b70 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 8a5fbfb8..951eeeab 100644 --- a/irc/server.go +++ b/irc/server.go @@ -970,26 +970,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(` ▄▄▄ ▄▄▄· ▄▄ • ▐ ▄ ▪ ▀▄ █·▐█ ▀█ ▐█ ▀ ▪▪ •█▌▐█▪