From 5d441ebbce6066c3636168ec5332ae9c2bdb8607 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 1 Oct 2026 06:55:14 -0700 Subject: Serve a shared snapshot for the public feed Build the default Popular feed once on the server and let browsers verify and paint its signed events before slow media finishes. Keep custom relays, pagination, filtering, and relay fallback on their existing paths.\n\nAdd stale-while-refresh persistence, service-worker bypass, development integration, and unit/browser coverage. --- src/popular-feed.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/popular-feed.js (limited to 'src/popular-feed.js') diff --git a/src/popular-feed.js b/src/popular-feed.js new file mode 100644 index 0000000..999ebc1 --- /dev/null +++ b/src/popular-feed.js @@ -0,0 +1,16 @@ +// Shared by the relay fallback and the server's public snapshot builder. +export const PUBLIC_FEED_RELAYS = ['wss://relay.coinos.io', 'wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.primal.net']; +export function popularCandidates(reactions) { + const counts = new Map(); + for (const r of reactions) { + const who = r.kind === 9735 ? (r.tags.find((x) => x[0] === 'P')?.[1] || r.pubkey) : r.pubkey; + for (const x of r.tags) if (x[0] === 'e' && /^[0-9a-f]{64}$/.test(x[1] || '')) { + if (!counts.has(x[1])) counts.set(x[1], new Set()); + counts.get(x[1]).add(who); + } + } + return { + ids: [...counts].filter(([, s]) => s.size >= 2).sort((a, b) => b[1].size - a[1].size).slice(0, 80).map(([id]) => id), + qualifies: (e) => e?.kind === 1 && (counts.get(e.id)?.size || 0) - (counts.get(e.id)?.has(e.pubkey) ? 1 : 0) >= 2, + }; +} -- cgit v1.2.3