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