aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-10 07:45:07 -0700
committerAdam Soltys <[email protected]>2026-10-10 07:45:07 -0700
commit9abd654e8ef57de59a4f4bd5cbfbba560ed7e523 (patch)
tree364dfe926baef25784c68a3c8af632ba789755e6 /src/features
parent79b09acc3c4c471fb29bb8d6994c26e849b90bb9 (diff)
downloadcoinosv3-9abd654e8ef57de59a4f4bd5cbfbba560ed7e523.tar.gz
coinosv3-9abd654e8ef57de59a4f4bd5cbfbba560ed7e523.zip
Feed: reposts. Amethyst showed Zapstore's repost of LWB's "Tankful" post in Adam's follows; we showed nothing — a feed asked only for posts (kinds 1, 1068). A feed of people now asks for their reposts too (NIP-18 kind 6; topic and firehose asks stay posts-only), and a repost shows as the note itself, under "🔁 <name> reposted" — its reactions, zaps, ⋯ and thread are the note's. Only reposts that carry the note and whose copy checks out (kind 1/1068, the id the e tag names, a valid signature); a muted author's note stays out. A note shows once: as itself, or under the first repost of it to arrive, counting rows still warming at the door. Media grids skip reposts. tools/feed-repost-test.js
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'src/features')
-rw-r--r--src/features/messages.js65
1 files changed, 56 insertions, 9 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index cab7a97..99b5c48 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -43,6 +43,7 @@ import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
import { sha256 } from '@noble/hashes/sha256';
import { base64urlnopad } from '@scure/base';
import { t, getLang } from '../i18n.js';
+import { verifyEvent } from 'nostr-tools/pure';
import { createGifPicker, gifMedia } from '../gif-picker.js';
import { inLanguage, isMachinePost, guessLang } from '../lang-guess.js';
import { translatePieces, translatable as transParts } from '../translate-split.js';
@@ -537,6 +538,28 @@ export function messagesFeature(ctx) {
const toOwnInbox = (wrap) => { if (ownInbox.length) publishOn(ownInbox, wrap, { onauth: relayAuth }); };
// what a feed or a profile lists: notes, and polls (NIP-88)
const FEED_KINDS = [1, 1068];
+ // A repost (NIP-18 kind 6) of someone's note shows in a feed of the
+ // people who reposted it, as the note itself under "<name> reposted".
+ // Only reposts that carry the note (every major client embeds it) and
+ // whose copy checks out: the id it names, a valid signature.
+ const REPOST = 6;
+ const repostInners = new Map(); // repost id -> the note, or null
+ function repostInner(ev) {
+ if (!ev || ev.kind !== REPOST) return null;
+ if (repostInners.has(ev.id)) return repostInners.get(ev.id);
+ let inner = null;
+ try {
+ const e = JSON.parse(ev.content || 'null');
+ const named = (ev.tags || []).filter((x) => x[0] === 'e').map((x) => x[1]);
+ if (e && FEED_KINDS.includes(e.kind) && typeof e.id === 'string' && (!named.length || named.includes(e.id)) && verifyEvent(e)) {
+ inner = { id: e.id, pubkey: e.pubkey, created_at: e.created_at, kind: e.kind, tags: e.tags, content: e.content, sig: e.sig };
+ }
+ } catch {}
+ if (repostInners.size > 2000) repostInners.delete(repostInners.keys().next().value);
+ repostInners.set(ev.id, inner);
+ return inner;
+ }
+ let repostBy = null; // set while noteRow draws a repost's note
// A profile shows its articles (NIP-23) among the notes, as Amethyst does.
const PROFILE_KINDS = [...FEED_KINDS, 30023];
// An edited article is a new event at the same address: keep the newest.
@@ -5781,7 +5804,8 @@ export function messagesFeature(ctx) {
try {
const orT = orTopicsOf(def);
await Promise.all([
- queryFeed(feedRelaysOr(def, def && def.all ? FIREHOSE_RELAYS : NOTE_RELAYS), { kinds: FEED_KINDS, limit: FEED_PAGE,
+ // people's reposts with their posts (a topic or firehose ask: posts only)
+ queryFeed(feedRelaysOr(def, def && def.all ? FIREHOSE_RELAYS : NOTE_RELAYS), { kinds: authors.length && !topics.length ? [...FEED_KINDS, REPOST] : FEED_KINDS, limit: FEED_PAGE,
...(authors.length ? { authors } : {}), ...(topics.length ? { '#t': topics } : {}) }, merge, c, 3000),
orT.length ? queryFeed(feedRelaysOr(def, TOPIC_RELAYS), { kinds: FEED_KINDS, limit: FEED_PAGE, '#t': orT }, merge, c, 3000) : null]);
} catch {} finally {
@@ -6527,6 +6551,7 @@ export function messagesFeature(ctx) {
if (p?.picture) makeThumb(pk, p);
}
async function noteReady(ev, deadline = Date.now() + READY_MS, depth = 0) {
+ if (ev && ev.kind === REPOST) { const inner = repostInner(ev); if (!inner) return; ev = inner; }
const tasks = [warmAvatar(ev.pubkey, deadline), ...noteMediaUrls(ev.content).map((u) => warmMedia(u, { thumb: true })),
...(learnVideoMeta(ev), noteVideoUrls(ev.content).map((u) => warmVideo(u, imetaDim(ev, u)))),
...notePreviewUrls(ev.content).map(warmPreview),
@@ -6605,13 +6630,20 @@ export function messagesFeature(ctx) {
if (!staged) feedStaged.set(c, staged = new Set());
const known = new Set([...c.notes, ...(c.deferred || [])].map((e) => e.id));
for (const e of evs || []) noteForSpam(e);
- let add = (evs || []).filter((e) => FEED_KINDS.includes(e.kind) && !isReply(e) && !hidden(e)
- && !known.has(e.id) && !staged.has(e.id) && known.add(e.id) && staged.add(e.id));
+ // A note shows once: as itself, or under the first repost of it to
+ // arrive — counting the ones still warming at the door.
+ // (`staged` holds the note's id too, for a repost)
+ const noteOf = (e) => (e.kind === REPOST ? repostInner(e) : e);
+ const notesIn = new Set([...c.notes, ...(c.deferred || [])].map((e) => noteOf(e)?.id).filter(Boolean));
+ const fresh = (e) => { const n = noteOf(e); return !!n && !notesIn.has(n.id) && !staged.has(n.id); };
+ const unstage = (e) => { staged.delete(e.id); const n = noteOf(e); if (n) staged.delete(n.id); };
+ let add = (evs || []).filter((e) => (e.kind === REPOST ? !!repostInner(e) && !hidden(repostInner(e)) : FEED_KINDS.includes(e.kind) && !isReply(e)) && !hidden(e)
+ && fresh(e) && !known.has(e.id) && !staged.has(e.id) && known.add(e.id) && staged.add(e.id) && staged.add(noteOf(e).id));
if (!add.length) return false;
const def = feedDef(c.id);
if (def && def.curated) {
const kept = curateFeed(add);
- for (const e of add) if (!kept.includes(e)) staged.delete(e.id);
+ for (const e of add) if (!kept.includes(e)) unstage(e);
add = kept;
if (!add.length) return false;
}
@@ -6621,7 +6653,7 @@ export function messagesFeature(ctx) {
// Paint text now using the same progressive rows as the local cache;
// slow media/quotes must not hold the whole first page behind a spinner.
c.booting = true;
- for (const e of add) staged.delete(e.id);
+ for (const e of add) unstage(e);
admitFeed(add, c);
c.boot = notesReady(c.notes.slice(0, FEED_PAGE)).finally(() => {
c.booting = false;
@@ -6635,7 +6667,7 @@ export function messagesFeature(ctx) {
// cannot hold ready text posts (or their new-post notice) behind it.
const ready = await Promise.all(add.map(async (e) => {
await noteReady(e);
- staged.delete(e.id);
+ unstage(e);
if (c.stopped) return false;
// Cached rows can still be warming. This new row is already prepared
// and can take its stable presentation without waiting for that page.
@@ -6882,7 +6914,9 @@ export function messagesFeature(ctx) {
const chunks = [];
for (let i = 0; i < a.length; i += REQ_AUTHORS) chunks.push(a.slice(i, i + REQ_AUTHORS));
return chunks.map(async (chunk) => {
- if (await queryFeed(relays, { kinds, authors: chunk, ...tag, limit, ...extra }, merge, c)) got = true;
+ // the people's reposts too, unless this pass asks for particular kinds
+ const ks = kinds === FEED_KINDS && !topics.length ? [...kinds, REPOST] : kinds;
+ if (await queryFeed(relays, { kinds: ks, authors: chunk, ...tag, limit, ...extra }, merge, c)) got = true;
});
}));
};
@@ -7082,7 +7116,7 @@ export function messagesFeature(ctx) {
const plan = feedRelays(def) ? [{ relays: feedRelays(def), authors }] : outboxPlan(authors);
for (const { relays, authors: a } of plan)
for (let i = 0; i < a.length; i += REQ_AUTHORS)
- feedUnsubs.push(subscribeOn(relays, { kinds: FEED_KINDS, authors: a.slice(i, i + REQ_AUTHORS), ...tag, since }, on));
+ feedUnsubs.push(subscribeOn(relays, { kinds: topics.length ? FEED_KINDS : [...FEED_KINDS, REPOST], authors: a.slice(i, i + REQ_AUTHORS), ...tag, since }, on));
}
function stopFeedWatch() {
for (const u of feedUnsubs) { try { u(); } catch {} }
@@ -9472,6 +9506,17 @@ export function messagesFeature(ctx) {
}
function noteRow(pk, ev, name, { open = true, focus = false, joined = false } = {}) {
+ if (ev.kind === REPOST) {
+ const inner = repostInner(ev);
+ if (!inner) return h('div', { class: 'row note-post', style: 'display:none' });
+ const prev = repostBy;
+ repostBy = ev.pubkey;
+ try { return noteRow(inner.pubkey, inner, displayName(inner.pubkey), { open, focus, joined }); }
+ finally { repostBy = prev; }
+ }
+ // who reposted this, for its header line (only this row: a quote inside draws none)
+ const reposter = repostBy;
+ repostBy = null;
// A zap receipt (9735, or coinos's 9737) reached as a reply or through a
// reaction to it — some clients let you react to a zap — is the zap, not
// a post by the lightning server that signed it: the zapper's face and
@@ -9526,6 +9571,8 @@ export function messagesFeature(ctx) {
// row — its handler stops propagation, so the row still opens the thread
avatar(pk, 'chat-avatar note-avatar'),
h('div', { class: 'note-content' },
+ reposter ? h('div', { class: 'small faint note-reposted', onClick: (e) => { e.stopPropagation(); openProfile(reposter); } },
+ h('span', { 'aria-hidden': 'true' }, '\u{1F501} '), t('postRepostedBy', { name: displayName(reposter) })) : null,
h('div', { class: 'row between note-header', style: 'align-items:center;gap:8px' },
h('div', { class: 'row', style: 'gap:7px;align-items:baseline;min-width:0' },
h('span', {
@@ -10949,7 +10996,7 @@ export function messagesFeature(ctx) {
// for more picks up where it stopped instead of re-reading the relays.
const mediaIdx = new Map(); // key -> { key, images: Map, videos: Map, checked: Set, until, end, loaded }
const mediaIdxKey = (feedId) => (mePk() || 'visitor') + '|' + feedId;
- const hasMediaOf = (ev, kind) => kind === 'videos' ? noteVideoUrls(ev.content).length > 0
+ const hasMediaOf = (ev, kind) => ev.kind === REPOST ? false : kind === 'videos' ? noteVideoUrls(ev.content).length > 0
: noteMediaUrls(ev.content).some((u) => !u.startsWith('https://i.ytimg.com/'));
function mediaIndex(feedId) {
const key = mediaIdxKey(feedId);