From c019fa3ab2e633ece2d991615d13d0c4c5e95538 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 13 Feb 2019 15:29:36 -0500 Subject: [PATCH] fix #375 --- irc/handlers.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index 64534610..d00ff317 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -555,19 +555,21 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r newRb := NewResponseBuffer(client) newRb.Label = rb.Label // same label, new batch // TODO: send `WARN CHATHISTORY MAX_MESSAGES_EXCEEDED` when appropriate - if !success { - newRb.Add(nil, server.name, "ERR", "CHATHISTORY", "NEED_MORE_PARAMS") - } else if hist == nil { + if hist == nil { newRb.Add(nil, server.name, "ERR", "CHATHISTORY", "NO_SUCH_CHANNEL") } else if len(items) == 0 { newRb.Add(nil, server.name, "ERR", "CHATHISTORY", "NO_TEXT_TO_SEND") + } else if !success { + newRb.Add(nil, server.name, "ERR", "CHATHISTORY", "NEED_MORE_PARAMS") } newRb.Send(true) }() target := msg.Params[0] channel = server.channels.Get(target) - if channel != nil { + if channel != nil && channel.hasClient(client) { + // "If [...] the user does not have permission to view the requested content, [...] + // NO_SUCH_CHANNEL SHOULD be returned" hist = &channel.history } else { targetClient := server.clients.Get(target) @@ -1019,7 +1021,7 @@ func historyHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R target := msg.Params[0] var hist *history.Buffer channel := server.channels.Get(target) - if channel != nil { + if channel != nil && channel.hasClient(client) { hist = &channel.history } else { if strings.ToLower(target) == "me" { @@ -1036,7 +1038,11 @@ func historyHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R } if hist == nil { - rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), target, client.t("No such channel")) + if channel == nil { + rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), target, client.t("No such channel")) + } else { + rb.Add(nil, server.name, ERR_NOTONCHANNEL, client.Nick(), target, client.t("You're not on that channel")) + } return false }