diff --git a/irc/handlers.go b/irc/handlers.go index 70b79720..8f1e6ad7 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2637,8 +2637,30 @@ func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo } } } else { + // Construct set of channels the client is in. + userChannels := make(map[*Channel]bool) + for _, channel := range client.Channels() { + userChannels[channel] = true + } + + // Another client is a friend if they share at least one channel, or they are the same client. + isFriend := func(otherClient *Client) bool { + if client == otherClient { + return true + } + + for _, channel := range otherClient.Channels() { + if userChannels[channel] { + return true + } + } + return false + } + for mclient := range server.clients.FindAll(mask) { - client.rplWhoReply(nil, mclient, rb) + if isOper || !mclient.HasMode(modes.Invisible) || isFriend(mclient) { + client.rplWhoReply(nil, mclient, rb) + } } }