Add CHATHISTORY LATEST support

This patch adds a bit more compliance to the chathistory IRCv3 specification.
This commit is contained in:
Thomas Vigouroux 2021-11-18 20:41:27 +01:00 committed by Simon Ser
parent cec335ee9c
commit 4831b61186

View file

@ -2380,7 +2380,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
var target, limitStr string var target, limitStr string
var boundsStr [2]string var boundsStr [2]string
switch subcommand { switch subcommand {
case "AFTER", "BEFORE": case "AFTER", "BEFORE", "LATEST":
if err := parseMessageParams(msg, nil, &target, &boundsStr[0], &limitStr); err != nil { if err := parseMessageParams(msg, nil, &target, &boundsStr[0], &limitStr); err != nil {
return err return err
} }
@ -2399,7 +2399,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
return err return err
} }
default: default:
// TODO: support LATEST, AROUND // TODO: support AROUND
return ircError{&irc.Message{ return ircError{&irc.Message{
Command: "FAIL", Command: "FAIL",
Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, "Unknown command"}, Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, "Unknown command"},
@ -2429,7 +2429,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
// TODO: support msgid criteria // TODO: support msgid criteria
var bounds [2]time.Time var bounds [2]time.Time
bounds[0] = parseChatHistoryBound(boundsStr[0]) bounds[0] = parseChatHistoryBound(boundsStr[0])
if bounds[0].IsZero() { if subcommand == "LATEST" && boundsStr[0] == "*" {
bounds[0] = time.Now();
} else if bounds[0].IsZero() {
return ircError{&irc.Message{ return ircError{&irc.Message{
Command: "FAIL", Command: "FAIL",
Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, boundsStr[0], "Invalid first bound"}, Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, boundsStr[0], "Invalid first bound"},
@ -2458,7 +2460,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
var history []*irc.Message var history []*irc.Message
switch subcommand { switch subcommand {
case "BEFORE": case "BEFORE", "LATEST":
history, err = store.LoadBeforeTime(ctx, &network.Network, entity, bounds[0], time.Time{}, limit, eventPlayback) history, err = store.LoadBeforeTime(ctx, &network.Network, entity, bounds[0], time.Time{}, limit, eventPlayback)
case "AFTER": case "AFTER":
history, err = store.LoadAfterTime(ctx, &network.Network, entity, bounds[0], time.Now(), limit, eventPlayback) history, err = store.LoadAfterTime(ctx, &network.Network, entity, bounds[0], time.Now(), limit, eventPlayback)