From 8e852cc7e4f1ea57e9837cd84581d92eefc5c07d Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 15 Apr 2020 11:29:15 +0200 Subject: [PATCH] Add support for downstream batch & chathistory --- downstream.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/downstream.go b/downstream.go index d289988..a3c8c66 100644 --- a/downstream.go +++ b/downstream.go @@ -427,7 +427,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error { } } - caps := []string{"message-tags", "server-time", "echo-message"} + caps := []string{"message-tags", "server-time", "echo-message", "batch"} if dc.capVersion >= 302 { caps = append(caps, "sasl=PLAIN") @@ -480,7 +480,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error { } switch name { - case "sasl", "message-tags", "server-time", "echo-message": + case "sasl", "message-tags", "server-time", "echo-message", "batch": dc.caps[name] = enable default: ack = false @@ -716,6 +716,15 @@ func (dc *downstreamConn) sendNetworkHistory(net *network) { return } + batchRef := "history" + if dc.caps["batch"] { + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: "BATCH", + Params: []string{"+" + batchRef, "chathistory", dc.marshalEntity(uc, target)}, + }) + } + for { msg := consumer.Consume() if msg == nil { @@ -734,8 +743,21 @@ func (dc *downstreamConn) sendNetworkHistory(net *network) { continue } + if dc.caps["batch"] { + msg = msg.Copy() + msg.Tags["batch"] = irc.TagValue(batchRef) + } + dc.SendMessage(dc.marshalMessage(msg, uc)) } + + if dc.caps["batch"] { + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: "BATCH", + Params: []string{"-" + batchRef}, + }) + } } }