From b3cfcc1289b7538c07a56458a97dd9824ab79063 Mon Sep 17 00:00:00 2001 From: Alex Jaspersen Date: Thu, 7 May 2020 03:00:28 +0000 Subject: [PATCH] Show users in WHO queries if they are friends, i.e. they share a channel. --- irc/client.go | 15 +++++++++++++++ irc/handlers.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/irc/client.go b/irc/client.go index b636678a..eb44cc9b 100644 --- a/irc/client.go +++ b/irc/client.go @@ -1022,6 +1022,21 @@ func (client *Client) ModeString() (str string) { return "+" + client.modes.String() } +// IsFriend() returns true if the given otherClient shares a channel with this client, or if they are the same user. +func (client *Client) IsFriend(otherClient *Client) bool { + if client == otherClient { + return true + } + + for _, channel := range client.Channels() { + if channel.hasClient(otherClient) { + return true + } + } + + return false +} + // Friends refers to clients that share a channel with this client. func (client *Client) Friends(capabs ...caps.Capability) (result map[*Session]bool) { result = make(map[*Session]bool) diff --git a/irc/handlers.go b/irc/handlers.go index 3c7dfb1e..fd53dd41 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2637,7 +2637,7 @@ func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo } } else { for mclient := range server.clients.FindAll(mask) { - if !mclient.HasMode(modes.Invisible) || isOper { + if isOper || !mclient.HasMode(modes.Invisible) || mclient.IsFriend(client) { client.rplWhoReply(nil, mclient, rb) } }