From 28d4971f366e9cb101a37f3904f605cf093dc549 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 24 Jul 2020 02:37:36 -0400 Subject: [PATCH 1/2] fix #1204 --- irc/channel.go | 35 +++++------------------------------ irc/handlers.go | 25 ++++++------------------- irc/responsebuffer.go | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 30ab0db5..483a8009 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -1246,44 +1246,19 @@ func (channel *Channel) SendSplitMessage(command string, minPrefixMode modes.Mod } // send echo-message - if rb.session.capabilities.Has(caps.EchoMessage) { - var tagsToUse map[string]string - if rb.session.capabilities.Has(caps.MessageTags) { - tagsToUse = clientOnlyTags - } - if histType == history.Tagmsg && rb.session.capabilities.Has(caps.MessageTags) { - rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, tagsToUse, command, chname) - } else { - rb.AddSplitMessageFromClient(details.nickMask, details.accountName, tagsToUse, command, chname, message) - } - } - // send echo-message to other connected sessions - for _, session := range client.Sessions() { - if session == rb.session { - continue - } - var tagsToUse map[string]string - if session.capabilities.Has(caps.MessageTags) { - tagsToUse = clientOnlyTags - } - if histType == history.Tagmsg && session.capabilities.Has(caps.MessageTags) { - session.sendFromClientInternal(false, message.Time, message.Msgid, details.nickMask, details.accountName, tagsToUse, command, chname) - } else if histType != history.Tagmsg { - session.sendSplitMsgFromClientInternal(false, details.nickMask, details.accountName, tagsToUse, command, chname, message) - } - } + rb.addEchoMessage(details, command, message, clientOnlyTags, chname) for _, member := range channel.Members() { - // echo-message is handled above, so skip sending the msg to the user themselves as well - if member == client { - continue - } if minPrefixMode != modes.Mode(0) && !channel.ClientIsAtLeast(member, minPrefixMode) { // STATUSMSG continue } for _, session := range member.Sessions() { + if session == rb.session { + continue // we already sent echo-message, if applicable + } + if isCTCP && session.isTor { continue // #753 } diff --git a/irc/handlers.go b/irc/handlers.go index 48391eb8..c31a7e75 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2041,18 +2041,16 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi service, isService := OragonoServices[lowercaseTarget] _, isZNC := zncHandlers[lowercaseTarget] - if histType == history.Privmsg { + if isService || isZNC { + rb.addEchoMessage(client.Details(), command, message, tags, target) + if histType != history.Privmsg { + return // NOTICE and TAGMSG to services are ignored + } if isService { servicePrivmsgHandler(service, server, client, message.Message, rb) - return } else if isZNC { zncPrivmsgHandler(client, lowercaseTarget, message.Message, rb) - return } - } - - // NOTICE and TAGMSG to services are ignored - if isService || isZNC { return } @@ -2110,18 +2108,7 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi } // the originating session may get an echo message: - if rb.session.capabilities.Has(caps.EchoMessage) { - hasTagsCap := rb.session.capabilities.Has(caps.MessageTags) - if histType == history.Tagmsg && hasTagsCap { - rb.AddFromClient(message.Time, message.Msgid, nickMaskString, accountName, tags, command, tnick) - } else { - tagsToSend := tags - if !hasTagsCap { - tagsToSend = nil - } - rb.AddSplitMessageFromClient(nickMaskString, accountName, tagsToSend, command, tnick, message) - } - } + rb.addEchoMessage(details, command, message, tags, tnick) if histType != history.Notice { //TODO(dan): possibly implement cooldown of away notifications to users if away, awayMessage := user.Away(); away { diff --git a/irc/responsebuffer.go b/irc/responsebuffer.go index 4dde2050..8eb5bdde 100644 --- a/irc/responsebuffer.go +++ b/irc/responsebuffer.go @@ -143,6 +143,23 @@ func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAcc } } +func (rb *ResponseBuffer) addEchoMessage(details ClientDetails, command string, message utils.SplitMessage, tags map[string]string, target string) { + if rb.session.capabilities.Has(caps.EchoMessage) { + hasTagsCap := rb.session.capabilities.Has(caps.MessageTags) + if command == "TAGMSG" { + if hasTagsCap { + rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, tags, command, target) + } + } else { + tagsToSend := tags + if !hasTagsCap { + tagsToSend = nil + } + rb.AddSplitMessageFromClient(details.nickMask, details.accountName, tagsToSend, command, target, message) + } + } +} + func (rb *ResponseBuffer) sendBatchStart(blocking bool) { if rb.batchID != "" { // batch already initialized From 6d18a1a78cff74cf557898ecdc3b8ecea32c99dd Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 24 Jul 2020 02:55:46 -0400 Subject: [PATCH 2/2] tweak addEchoMessage signature --- irc/channel.go | 2 +- irc/handlers.go | 5 +++-- irc/responsebuffer.go | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 483a8009..2da18db1 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -1246,7 +1246,7 @@ func (channel *Channel) SendSplitMessage(command string, minPrefixMode modes.Mod } // send echo-message - rb.addEchoMessage(details, command, message, clientOnlyTags, chname) + rb.addEchoMessage(clientOnlyTags, details.nickMask, details.accountName, command, chname, message) for _, member := range channel.Members() { if minPrefixMode != modes.Mode(0) && !channel.ClientIsAtLeast(member, minPrefixMode) { diff --git a/irc/handlers.go b/irc/handlers.go index c31a7e75..5bcf027f 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2042,7 +2042,8 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi _, isZNC := zncHandlers[lowercaseTarget] if isService || isZNC { - rb.addEchoMessage(client.Details(), command, message, tags, target) + details := client.Details() + rb.addEchoMessage(tags, details.nickMask, details.accountName, command, target, message) if histType != history.Privmsg { return // NOTICE and TAGMSG to services are ignored } @@ -2108,7 +2109,7 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi } // the originating session may get an echo message: - rb.addEchoMessage(details, command, message, tags, tnick) + rb.addEchoMessage(tags, nickMaskString, accountName, command, tnick, message) if histType != history.Notice { //TODO(dan): possibly implement cooldown of away notifications to users if away, awayMessage := user.Away(); away { diff --git a/irc/responsebuffer.go b/irc/responsebuffer.go index 8eb5bdde..ab1fa551 100644 --- a/irc/responsebuffer.go +++ b/irc/responsebuffer.go @@ -143,19 +143,19 @@ func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAcc } } -func (rb *ResponseBuffer) addEchoMessage(details ClientDetails, command string, message utils.SplitMessage, tags map[string]string, target string) { +func (rb *ResponseBuffer) addEchoMessage(tags map[string]string, nickMask, accountName, command, target string, message utils.SplitMessage) { if rb.session.capabilities.Has(caps.EchoMessage) { hasTagsCap := rb.session.capabilities.Has(caps.MessageTags) if command == "TAGMSG" { if hasTagsCap { - rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, tags, command, target) + rb.AddFromClient(message.Time, message.Msgid, nickMask, accountName, tags, command, target) } } else { tagsToSend := tags if !hasTagsCap { tagsToSend = nil } - rb.AddSplitMessageFromClient(details.nickMask, details.accountName, tagsToSend, command, target, message) + rb.AddSplitMessageFromClient(nickMask, accountName, tagsToSend, command, target, message) } } }