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 == "" {