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

names should respect invisibility

This commit is contained in:
Shivaram Lingamneni 2019-04-23 01:52:26 -04:00
parent 30f6e11698
commit d6c970f521

View File

@ -335,38 +335,44 @@ func (channel *Channel) regenerateMembersCache() {
// Names sends the list of users joined to the channel to the given client. // Names sends the list of users joined to the channel to the given client.
func (channel *Channel) Names(client *Client, rb *ResponseBuffer) { func (channel *Channel) Names(client *Client, rb *ResponseBuffer) {
isJoined := channel.hasClient(client)
isMultiPrefix := rb.session.capabilities.Has(caps.MultiPrefix) isMultiPrefix := rb.session.capabilities.Has(caps.MultiPrefix)
isUserhostInNames := rb.session.capabilities.Has(caps.UserhostInNames) isUserhostInNames := rb.session.capabilities.Has(caps.UserhostInNames)
maxNamLen := 480 - len(client.server.name) - len(client.Nick()) maxNamLen := 480 - len(client.server.name) - len(client.Nick())
var namesLines []string var namesLines []string
var buffer bytes.Buffer var buffer bytes.Buffer
for _, target := range channel.Members() { if isJoined || !channel.flags.HasMode(modes.Secret) {
var nick string for _, target := range channel.Members() {
if isUserhostInNames { var nick string
nick = target.NickMaskString() if isUserhostInNames {
} else { nick = target.NickMaskString()
nick = target.Nick() } else {
} nick = target.Nick()
channel.stateMutex.RLock() }
modes := channel.members[target] channel.stateMutex.RLock()
channel.stateMutex.RUnlock() modeSet := channel.members[target]
if modes == nil { channel.stateMutex.RUnlock()
continue if modeSet == nil {
} continue
prefix := modes.Prefixes(isMultiPrefix) }
if buffer.Len()+len(nick)+len(prefix)+1 > maxNamLen { if !isJoined && target.flags.HasMode(modes.Invisible) {
namesLines = append(namesLines, buffer.String()) continue
buffer.Reset() }
prefix := modeSet.Prefixes(isMultiPrefix)
if buffer.Len()+len(nick)+len(prefix)+1 > maxNamLen {
namesLines = append(namesLines, buffer.String())
buffer.Reset()
}
if buffer.Len() > 0 {
buffer.WriteString(" ")
}
buffer.WriteString(prefix)
buffer.WriteString(nick)
} }
if buffer.Len() > 0 { if buffer.Len() > 0 {
buffer.WriteString(" ") namesLines = append(namesLines, buffer.String())
} }
buffer.WriteString(prefix)
buffer.WriteString(nick)
}
if buffer.Len() > 0 {
namesLines = append(namesLines, buffer.String())
} }
for _, line := range namesLines { for _, line := range namesLines {