GET /api/v1/history took a database id for before, but history responses carry only each message's id, so a client had nothing to pass for the next page. before now takes that id: the server finds the message among those sent to the target and returns the page older than it. An id with no such message gets 400 "unknown before id" instead of a silent full page. A handler test pages back through a channel using only ids from earlier responses, and README.md's history section describes the new parameter. Model: opus-5-5 Co-authored-by: clawbot <sneak+clawbot@sneak.cloud>
This commit was merged in pull request #136.
This commit is contained in:
+20
-3
@@ -1058,17 +1058,34 @@ func (database *Database) PollMessages(
|
||||
return msgs, lastQID, nil
|
||||
}
|
||||
|
||||
// GetHistory returns message history for a target.
|
||||
// GetHistory returns message history for a target. A
|
||||
// non-empty before is the id of a message sent to target,
|
||||
// and only messages older than it are returned; an id with
|
||||
// no such message gives an error wrapping sql.ErrNoRows.
|
||||
func (database *Database) GetHistory(
|
||||
ctx context.Context,
|
||||
target string,
|
||||
beforeID int64,
|
||||
target, before string,
|
||||
limit int,
|
||||
) ([]IRCMessage, error) {
|
||||
if limit <= 0 {
|
||||
limit = defaultHistLimit
|
||||
}
|
||||
|
||||
var beforeID int64
|
||||
|
||||
if before != "" {
|
||||
err := database.conn.QueryRowContext(ctx,
|
||||
`SELECT id FROM messages
|
||||
WHERE uuid = ? AND msg_to = ?`,
|
||||
before, target,
|
||||
).Scan(&beforeID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"find message %q: %w", before, err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
rows, err := database.queryHistory(
|
||||
ctx, target, beforeID, limit,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user