fix: message list now returns most recent 50, not oldest 50

Query was ORDER BY ASC LIMIT 50 — returning the 50 oldest messages.
On page refresh users saw ancient messages instead of recent ones.
Changed to ORDER BY DESC LIMIT then reverse in Go so the API still
returns chronological order but from the bottom of the history.
This commit is contained in:
2026-07-02 09:19:31 -04:00
parent f4c5fae10a
commit b28e072e81
+7 -2
View File
@@ -486,7 +486,7 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
FROM messages m
JOIN users u ON m.author_id = u.id
WHERE m.channel_id = $1 AND m.created_at < (SELECT created_at FROM messages WHERE id = $2)
ORDER BY m.created_at ASC
ORDER BY m.created_at DESC
LIMIT $3
`, channelID, before, limit)
} else {
@@ -495,7 +495,7 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
FROM messages m
JOIN users u ON m.author_id = u.id
WHERE m.channel_id = $1
ORDER BY m.created_at ASC
ORDER BY m.created_at DESC
LIMIT $2
`, channelID, limit)
}
@@ -527,6 +527,11 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
messages = h.attachEmbeds(r.Context(), messages)
// Reverse: query returns DESC (newest first), client expects ASC (oldest first).
for i, j := 0, len(messages)-1; i < j; i, j = i+1, j-1 {
messages[i], messages[j] = messages[j], messages[i]
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(messages)