From 246f09c71ec52e5fe7c07d31a547bd21fd78cac5 Mon Sep 17 00:00:00 2001 From: you Date: Wed, 18 Mar 2026 23:30:13 +0000 Subject: [PATCH] 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. --- server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index e16493a3..d38df80c 100644 --- a/server.js +++ b/server.js @@ -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) => {