From baadb964bc99a8c8642cfc794970781f8217c843 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Apr 2020 21:34:45 +0200 Subject: [PATCH] Add origin argument to upstreamConn.produce --- downstream.go | 9 +-------- upstream.go | 12 +++++++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/downstream.go b/downstream.go index e2681db..cca60d0 100644 --- a/downstream.go +++ b/downstream.go @@ -1187,14 +1187,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { } uc.appendLog(upstreamName, echoMsg) - - uc.network.ring.Produce(echoMsg) - - uc.forEachDownstream(func(c *downstreamConn) { - if c != dc || c.caps["echo-message"] { - c.sendFromUpstream(echoMsg, uc) - } - }) + uc.produce(echoMsg, dc) } case "NOTICE": var targetsStr, text string diff --git a/upstream.go b/upstream.go index 46f2183..ae6f48c 100644 --- a/upstream.go +++ b/upstream.go @@ -247,7 +247,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { return nil case "NOTICE": if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message - uc.produce(msg) + uc.produce(msg, nil) } else { // regular user NOTICE var entity, text string if err := parseMessageParams(msg, &entity, &text); err != nil { @@ -260,7 +260,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.appendLog(target, msg) - uc.produce(msg) + uc.produce(msg, nil) } case "CAP": var subCmd string @@ -1136,7 +1136,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.appendLog(target, msg) - uc.produce(msg) + uc.produce(msg, nil) case "INVITE": var nick string var channel string @@ -1364,11 +1364,13 @@ func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) { } } -func (uc *upstreamConn) produce(msg *irc.Message) { +func (uc *upstreamConn) produce(msg *irc.Message, origin *downstreamConn) { uc.network.ring.Produce(msg) uc.forEachDownstream(func(dc *downstreamConn) { - dc.sendFromUpstream(msg, uc) + if dc != origin || dc.caps["echo-message"] { + dc.sendFromUpstream(msg, uc) + } }) }