downstream: drop downstreamConn.marshalMessage

It's a no-op.
This commit is contained in:
Simon Ser 2022-08-05 18:57:38 +02:00
parent 25257b8892
commit 31957a9ac4
2 changed files with 8 additions and 41 deletions

View File

@ -637,39 +637,6 @@ func (dc *downstreamConn) handlePong(token string) {
dc.ackMsgID(msgID) 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 { func (dc *downstreamConn) handleMessage(ctx context.Context, msg *irc.Message) error {
ctx, cancel := dc.conn.NewContext(ctx) ctx, cancel := dc.conn.NewContext(ctx)
defer cancel() defer cancel()
@ -1644,7 +1611,7 @@ func (dc *downstreamConn) sendTargetBacklog(ctx context.Context, net *network, t
} }
} else { } else {
msg.Tags["batch"] = batchRef 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) { dc.SendBatch("chathistory", []string{target}, nil, func(batchRef irc.TagValue) {
for _, msg := range history { for _, msg := range history {
msg.Tags["batch"] = batchRef msg.Tags["batch"] = batchRef
dc.SendMessage(dc.marshalMessage(msg, network)) dc.SendMessage(msg)
} }
}) })
case "READ", "MARKREAD": 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) { dc.SendBatch("soju.im/search", nil, nil, func(batchRef irc.TagValue) {
for _, msg := range messages { for _, msg := range messages {
msg.Tags["batch"] = batchRef msg.Tags["batch"] = batchRef
dc.SendMessage(dc.marshalMessage(msg, uc.network)) dc.SendMessage(msg)
} }
}) })
case "BOUNCER": case "BOUNCER":

View File

@ -968,7 +968,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
if !me { if !me {
uc.forEachDownstream(func(dc *downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc.network)) dc.SendMessage(msg)
}) })
} else { } else {
uc.forEachDownstream(func(dc *downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
@ -993,7 +993,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
}) })
} else { } else {
uc.forEachDownstream(func(dc *downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc.network)) dc.SendMessage(msg)
}) })
} }
case "CHGHOST": case "CHGHOST":
@ -1019,7 +1019,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
} else { } else {
uc.forEachDownstream(func(dc *downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
// TODO: add fallback with QUIT/JOIN/MODE messages // TODO: add fallback with QUIT/JOIN/MODE messages
dc.SendMessage(dc.marshalMessage(msg, uc.network)) dc.SendMessage(msg)
}) })
} }
case "JOIN": case "JOIN":
@ -1113,7 +1113,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
if msg.Prefix.Name != uc.nick { if msg.Prefix.Name != uc.nick {
uc.forEachDownstream(func(dc *downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc.network)) dc.SendMessage(msg)
}) })
} }
case irc.RPL_TOPIC, irc.RPL_NOTOPIC: 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) { uc.forEachDownstream(func(dc *downstreamConn) {
echo := dc.id == originID && msg.Prefix != nil && uc.isOurNick(msg.Prefix.Name) echo := dc.id == originID && msg.Prefix != nil && uc.isOurNick(msg.Prefix.Name)
if !detached && (!echo || dc.caps.IsEnabled("echo-message")) { if !detached && (!echo || dc.caps.IsEnabled("echo-message")) {
dc.sendMessageWithID(dc.marshalMessage(msg, uc.network), msgID) dc.sendMessageWithID(msg, msgID)
} else { } else {
dc.advanceMessageWithID(msg, msgID) dc.advanceMessageWithID(msg, msgID)
} }