3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +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,12 +335,14 @@ 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
if isJoined || !channel.flags.HasMode(modes.Secret) {
for _, target := range channel.Members() { for _, target := range channel.Members() {
var nick string var nick string
if isUserhostInNames { if isUserhostInNames {
@ -349,12 +351,15 @@ func (channel *Channel) Names(client *Client, rb *ResponseBuffer) {
nick = target.Nick() nick = target.Nick()
} }
channel.stateMutex.RLock() channel.stateMutex.RLock()
modes := channel.members[target] modeSet := channel.members[target]
channel.stateMutex.RUnlock() channel.stateMutex.RUnlock()
if modes == nil { if modeSet == nil {
continue continue
} }
prefix := modes.Prefixes(isMultiPrefix) if !isJoined && target.flags.HasMode(modes.Invisible) {
continue
}
prefix := modeSet.Prefixes(isMultiPrefix)
if buffer.Len()+len(nick)+len(prefix)+1 > maxNamLen { if buffer.Len()+len(nick)+len(prefix)+1 > maxNamLen {
namesLines = append(namesLines, buffer.String()) namesLines = append(namesLines, buffer.String())
buffer.Reset() buffer.Reset()
@ -368,6 +373,7 @@ func (channel *Channel) Names(client *Client, rb *ResponseBuffer) {
if buffer.Len() > 0 { if buffer.Len() > 0 {
namesLines = append(namesLines, buffer.String()) namesLines = append(namesLines, buffer.String())
} }
}
for _, line := range namesLines { for _, line := range namesLines {
if buffer.Len() > 0 { if buffer.Len() > 0 {