Fix channels showing oldest messages instead of latest

Messages were sliced from the start (oldest first). Now returns the
last N messages so the chat view shows the most recent conversation.
This commit is contained in:
you
2026-03-18 23:30:13 +00:00
parent 5055135eb7
commit 246f09c71e
+7 -2
View File
@@ -1003,8 +1003,13 @@ app.get('/api/channels/:hash/messages', (req, res) => {
}
}
const messages = [...msgMap.values()].slice(Number(offset), Number(offset) + Number(limit));
res.json({ messages, total: msgMap.size });
const allMessages = [...msgMap.values()];
const total = allMessages.length;
// Return the latest messages (tail), not the oldest (head)
const start = Math.max(0, total - Number(limit) - Number(offset));
const end = total - Number(offset);
const messages = allMessages.slice(Math.max(0, start), Math.max(0, end));
res.json({ messages, total });
});
app.get('/api/observers', (req, res) => {