diff --git a/irc/channel.go b/irc/channel.go index 4eedd07a..eec9355a 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -944,7 +944,9 @@ func (channel *Channel) replayHistoryForResume(session *Session, after time.Time items, complete, _ = seq.Between(afterS, beforeS, channel.server.Config().History.ZNCMax) } rb := NewResponseBuffer(session) - channel.replayHistoryItems(rb, items, false) + if len(items) != 0 { + channel.replayHistoryItems(rb, items, false) + } if !complete && !session.resumeDetails.HistoryIncomplete { // warn here if we didn't warn already rb.Add(nil, histServMask, "NOTICE", channel.Name(), session.client.t("Some additional message history may have been lost")) @@ -961,10 +963,7 @@ func stripMaskFromNick(nickMask string) (nick string) { } func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) { - if len(items) == 0 { - return - } - + // send an empty batch if necessary, as per the CHATHISTORY spec chname := channel.Name() client := rb.target eventPlayback := rb.session.capabilities.Has(caps.EventPlayback) diff --git a/irc/client.go b/irc/client.go index 49d9b2db..85fc19c5 100644 --- a/irc/client.go +++ b/irc/client.go @@ -832,9 +832,11 @@ func (session *Session) playResume() { if !timestamp.IsZero() && privmsgSeq != nil { after := history.Selector{Time: timestamp} items, complete, _ := privmsgSeq.Between(after, history.Selector{}, config.History.ZNCMax) - rb := NewResponseBuffer(session) - client.replayPrivmsgHistory(rb, items, "", complete) - rb.Send(true) + if len(items) != 0 { + rb := NewResponseBuffer(session) + client.replayPrivmsgHistory(rb, items, "", complete) + rb.Send(true) + } } session.resumeDetails = nil @@ -844,12 +846,10 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I var batchID string details := client.Details() nick := details.nick - if 0 < len(items) { - if target == "" { - target = nick - } - batchID = rb.StartNestedHistoryBatch(target) + if target == "" { + target = nick } + batchID = rb.StartNestedHistoryBatch(target) allowTags := rb.session.capabilities.Has(caps.MessageTags) for _, item := range items { diff --git a/irc/handlers.go b/irc/handlers.go index 2546dddf..373c1a1a 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -525,7 +525,7 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r var err error defer func() { // successful responses are sent as a chathistory or history batch - if err == nil && 0 < len(items) { + if err == nil { if channel != nil { channel.replayHistoryItems(rb, items, false) } else { @@ -958,7 +958,7 @@ func historyHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R items, _, err = sequence.Between(start, end, limit) } - if err == nil { + if err == nil && len(items) != 0 { if channel != nil { channel.replayHistoryItems(rb, items, false) } else { diff --git a/irc/znc.go b/irc/znc.go index cd3ff783..c90e7144 100644 --- a/irc/znc.go +++ b/irc/znc.go @@ -124,7 +124,7 @@ func zncPlayPrivmsgs(client *Client, rb *ResponseBuffer, after, before time.Time } zncMax := client.server.Config().History.ZNCMax items, _, err := sequence.Between(history.Selector{Time: after}, history.Selector{Time: before}, zncMax) - if err == nil { + if err == nil && len(items) != 0 { client.replayPrivmsgHistory(rb, items, "", true) } }