From 6e2b2a44b87006b8b7873dbd98076582a3f0a3e1 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 20 Jan 2020 00:37:13 -0500 Subject: [PATCH] set the time of a multiline message at BATCH - --- irc/handlers.go | 7 ++++--- irc/utils/text.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index 8aa9917d..58b22288 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -352,8 +352,6 @@ func batchHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res } else { rb.session.batch.target = msg.Params[2] // save the response label for later - // XXX changing the label inside a handler is a bit dodgy, but it works here - // because there's no way we could have triggered a flush up to this point rb.session.batch.responseLabel = rb.Label rb.Label = "" } @@ -366,12 +364,15 @@ func batchHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res } else { batch := rb.session.batch rb.session.batch = MultilineBatch{} + // time tag should correspond to the time when the message was completed + batch.message.SetTime() histType, err := msgCommandToHistType(batch.command) if err != nil { histType = history.Privmsg batch.command = "PRIVMSG" } - // see previous caution about modifying ResponseBuffer.Label + // XXX changing the label inside a handler is a bit dodgy, but it works here + // because there's no way we could have triggered a flush up to this point rb.Label = batch.responseLabel dispatchMessageToTarget(client, batch.tags, histType, batch.command, batch.target, batch.message, rb) } diff --git a/irc/utils/text.go b/irc/utils/text.go index 1c8e3f2f..de240643 100644 --- a/irc/utils/text.go +++ b/irc/utils/text.go @@ -42,9 +42,6 @@ func MakeMessage(original string) (result SplitMessage) { } func (sm *SplitMessage) Append(message string, concat bool) { - if sm.Time.IsZero() { - sm.Time = time.Now().UTC() - } if sm.Msgid == "" { sm.Msgid = GenerateSecretToken() } @@ -54,6 +51,10 @@ func (sm *SplitMessage) Append(message string, concat bool) { }) } +func (sm *SplitMessage) SetTime() { + sm.Time = time.Now().UTC() +} + func (sm *SplitMessage) LenLines() int { if sm.Split == nil { if sm.Message == "" {