1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// Shared by the relay fallback and the server's public snapshot builder.
// Popular counts reactions, so it reads where the reactions are (measured
// 2026-10-04 over 30 min: ditto alone held 774 of 823 distinct reactions and
// 69 of the 74 posts two people touched; ditto + nos.lol had all 74; ditto
// keeps them for a month, nos.lol/primal ~5 days, damus ~1 day and caps a
// REQ at ~300). Ours stays in for coinos people's own activity.
export const POPULAR_RELAYS = ['wss://relay.ditto.pub', 'wss://nos.lol', 'wss://relay.primal.net', 'wss://relay.coinos.io'];
// Everything is every post: damus answers a bare kind-1 ask with nothing,
// and ditto's posts are ~30% fediverse bridged in by Mostr — both left out.
export const FIREHOSE_RELAYS = ['wss://relay.coinos.io', 'wss://nos.lol', 'wss://relay.primal.net'];
export const PUBLIC_FEED_RELAYS = POPULAR_RELAYS; // the server's Popular snapshot
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,
};
}
|