Changeset 1485933 in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
07/20/2026 07:35:55 AM (7 weeks ago)
Author:
Robin <roboburr@…>
Branches:
main
Children:
520e477
Parents:
7b04d3b
git-author:
Robin <roboburr@…> (07/20/2026 07:18:02 AM)
git-committer:
Robin <roboburr@…> (07/20/2026 07:35:55 AM)
Message:

Feature: Load more on Messages, page 72 (klonkt-demo-r9u, slice 2/4)

Messages now pages in 72s with the shared Load-more button instead of a
hard 80-item cap. getMessages gains an offset arg and pages the merged,
grouped stream by recomputing top-down and slicing [offset, offset+72]
(stable across pages); getNotifications' per-source caps scale with the
requested limit so deep paging can reach older items. The item markup
moved to partials/msg-item.ejs so the page and the append fragment
render identically. The client-side filter/search re-indexes appended
rows on htmx:afterSettle and re-applies the active chip, so search keeps
working across pages. Seen-watermark is only stamped on the first page,
not on appends.

Tests: getMessages offset paging (no overlap, PAGE+1 probe). Browser:
72 -> 144 -> 150 then the button drops; searching a term only present on
page 2 matches after append.

Co-Authored-By: Claude Opus 4.8 <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    r7b04d3b r1485933  
    777777router.get('/messages', requireSiteManager, (req, res) => {
    778778  const site = res.locals.site;
    779   const items = site ? ActivityPubService.getMessages(site.slug, 80) : [];
     779  const append = req.query.append === '1';
     780  const offset = Math.max(0, parseInt(req.query.offset, 10) || 0);
     781  const page = site ? ActivityPubService.getMessages(site.slug, FEED_PAGE + 1, offset) : [];
     782  const hasMore = page.length > FEED_PAGE;
     783  const items = page.slice(0, FEED_PAGE);
    780784  // Read the watermark BEFORE marking seen → unread dots on items newer than last visit.
    781785  const seenAt = site ? ActivityPubService.notificationsSeenAt(site.slug) : 0;
    782   if (site && !isViewer(req.session.user)) ActivityPubService.markNotificationsSeen(site.slug);
     786  // Only stamp "seen" on the first page load (not on Load-more appends).
     787  if (site && !append && !isViewer(req.session.user)) ActivityPubService.markNotificationsSeen(site.slug);
     788  const moreBase = res.locals.siteUrlBase || '';
     789  if (append) {
     790    return renderPage(req, res, 'partials/messages-append', { items, seen: seenAt, hasMore, nextOffset: offset + FEED_PAGE, moreBase });
     791  }
    783792  renderPage(req, res, 'pages/messages', {
    784793    pageTitleKey: 'msg.title', bodyClass: 'on-special', items, seenAt,
     794    hasMore, nextOffset: offset + FEED_PAGE, moreBase,
    785795    success: req.query.success || null, error: req.query.error || null,
    786796  });
Note: See TracChangeset for help on using the changeset viewer.