From 31957a9ac4f2ad425af9c61c6b53fddec86aea02 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 5 Aug 2022 18:57:38 +0200 Subject: [PATCH] downstream: drop downstreamConn.marshalMessage It's a no-op. --- downstream.go | 39 +++------------------------------------ upstream.go | 10 +++++----- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/downstream.go b/downstream.go index 846717d..7eedaff 100644 --- a/downstream.go +++ b/downstream.go @@ -637,39 +637,6 @@ func (dc *downstreamConn) handlePong(token string) { dc.ackMsgID(msgID) } -// marshalMessage re-formats a message coming from an upstream connection so -// that it's suitable for being sent on this downstream connection. Only -// messages that may appear in logs are supported, except MODE messages which -// may only appear in single-upstream mode. -func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Message { - msg = msg.Copy() - - if dc.network != nil { - return msg - } - - switch msg.Command { - case "PRIVMSG", "NOTICE", "TAGMSG": - msg.Params[0] = dc.marshalEntity(net, msg.Params[0]) - case "NICK": - // Nick change for another user - msg.Params[0] = dc.marshalEntity(net, msg.Params[0]) - case "JOIN", "PART": - msg.Params[0] = dc.marshalEntity(net, msg.Params[0]) - case "KICK": - msg.Params[0] = dc.marshalEntity(net, msg.Params[0]) - msg.Params[1] = dc.marshalEntity(net, msg.Params[1]) - case "TOPIC": - msg.Params[0] = dc.marshalEntity(net, msg.Params[0]) - case "QUIT", "SETNAME", "CHGHOST": - // This space is intentionally left blank - default: - panic(fmt.Sprintf("unexpected %q message", msg.Command)) - } - - return msg -} - func (dc *downstreamConn) handleMessage(ctx context.Context, msg *irc.Message) error { ctx, cancel := dc.conn.NewContext(ctx) defer cancel() @@ -1644,7 +1611,7 @@ func (dc *downstreamConn) sendTargetBacklog(ctx context.Context, net *network, t } } else { msg.Tags["batch"] = batchRef - dc.SendMessage(dc.marshalMessage(msg, net)) + dc.SendMessage(msg) } } }) @@ -2898,7 +2865,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. dc.SendBatch("chathistory", []string{target}, nil, func(batchRef irc.TagValue) { for _, msg := range history { msg.Tags["batch"] = batchRef - dc.SendMessage(dc.marshalMessage(msg, network)) + dc.SendMessage(msg) } }) case "READ", "MARKREAD": @@ -3086,7 +3053,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. dc.SendBatch("soju.im/search", nil, nil, func(batchRef irc.TagValue) { for _, msg := range messages { msg.Tags["batch"] = batchRef - dc.SendMessage(dc.marshalMessage(msg, uc.network)) + dc.SendMessage(msg) } }) case "BOUNCER": diff --git a/upstream.go b/upstream.go index 19ce562..32e7d88 100644 --- a/upstream.go +++ b/upstream.go @@ -968,7 +968,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err if !me { uc.forEachDownstream(func(dc *downstreamConn) { - dc.SendMessage(dc.marshalMessage(msg, uc.network)) + dc.SendMessage(msg) }) } else { uc.forEachDownstream(func(dc *downstreamConn) { @@ -993,7 +993,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err }) } else { uc.forEachDownstream(func(dc *downstreamConn) { - dc.SendMessage(dc.marshalMessage(msg, uc.network)) + dc.SendMessage(msg) }) } case "CHGHOST": @@ -1019,7 +1019,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err } else { uc.forEachDownstream(func(dc *downstreamConn) { // TODO: add fallback with QUIT/JOIN/MODE messages - dc.SendMessage(dc.marshalMessage(msg, uc.network)) + dc.SendMessage(msg) }) } case "JOIN": @@ -1113,7 +1113,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err if msg.Prefix.Name != uc.nick { uc.forEachDownstream(func(dc *downstreamConn) { - dc.SendMessage(dc.marshalMessage(msg, uc.network)) + dc.SendMessage(msg) }) } case irc.RPL_TOPIC, irc.RPL_NOTOPIC: @@ -2169,7 +2169,7 @@ func (uc *upstreamConn) produce(target string, msg *irc.Message, originID uint64 uc.forEachDownstream(func(dc *downstreamConn) { echo := dc.id == originID && msg.Prefix != nil && uc.isOurNick(msg.Prefix.Name) if !detached && (!echo || dc.caps.IsEnabled("echo-message")) { - dc.sendMessageWithID(dc.marshalMessage(msg, uc.network), msgID) + dc.sendMessageWithID(msg, msgID) } else { dc.advanceMessageWithID(msg, msgID) }