From 1d74185b7d3f85769d651bba7dcb7a57579ddbc5 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 12 Oct 2020 22:42:03 -0400 Subject: [PATCH] fix #1322 --- irc/handlers.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index d231205c..dcac15e7 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -550,25 +550,24 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r var sequence history.Sequence var err error defer func() { - // successful responses are sent as a chathistory or history batch - if err == nil { + // errors are sent either without a batch, or in a draft/labeled-response batch as usual + if unknown_command { + rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "UNKNOWN_COMMAND", utils.SafeErrorParam(msg.Params[0]), client.t("Unknown command")) + } else if err == utils.ErrInvalidParams { + rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "INVALID_PARAMS", msg.Params[0], client.t("Invalid parameters")) + } else if sequence == nil { + // send an empty batch as per the spec + batchID := rb.StartNestedHistoryBatch(utils.SafeErrorParam(target)) + rb.EndNestedBatch(batchID) + } else if err != nil { + rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "MESSAGE_ERROR", msg.Params[0], client.t("Messages could not be retrieved")) + } else { + // successful responses are sent as a chathistory or history batch if channel != nil { channel.replayHistoryItems(rb, items, false) } else { client.replayPrivmsgHistory(rb, items, target, true) } - return - } - - // errors are sent either without a batch, or in a draft/labeled-response batch as usual - if unknown_command { - rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "UNKNOWN_COMMAND", utils.SafeErrorParam(msg.Params[0]), client.t("Unknown command")) - } else if err == utils.ErrInvalidParams { - rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "INVALID_PARAMETERS", msg.Params[0], client.t("Invalid parameters")) - } else if err != nil { - rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "MESSAGE_ERROR", msg.Params[0], client.t("Messages could not be retrieved")) - } else if sequence == nil { - rb.Add(nil, server.name, "FAIL", "CHATHISTORY", "NO_SUCH_CHANNEL", utils.SafeErrorParam(msg.Params[1]), client.t("No such channel")) } }()