3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

Merge pull request #1163 from slingamn/list_issue1161

fix #1161
This commit is contained in:
Shivaram Lingamneni 2020-06-30 17:43:48 -07:00 committed by GitHub
commit 79764cd549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 22 deletions

View File

@ -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()) 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
}

View File

@ -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) clientIsOp := client.HasMode(modes.Operator)
if len(channels) == 0 { if len(channels) == 0 {
for _, channel := range server.channels.Channels() { for _, channel := range server.channels.Channels() {
@ -1537,7 +1544,7 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
continue continue
} }
if matcher.Matches(channel) { if matcher.Matches(channel) {
client.RplList(channel, rb) rplList(channel)
} }
} }
} else { } else {
@ -1555,7 +1562,7 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
continue continue
} }
if matcher.Matches(channel) { if matcher.Matches(channel) {
client.RplList(channel, rb) rplList(channel)
} }
} }
} }

View File

@ -970,26 +970,6 @@ func (matcher *elistMatcher) Matches(channel *Channel) bool {
return true 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 ( var (
infoString1 = strings.Split(` · infoString1 = strings.Split(` ·
· ·