aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/messages.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-11 23:04:15 -0700
committerAdam Soltys <[email protected]>2026-10-11 23:04:15 -0700
commit2b83c3f46c0dc2da1bbd9854443d57de54b979ea (patch)
tree44cf2eb1b315f798894d81504248874a67297b71 /src/features/messages.js
parent6eda01863920ae45d56a65563a7f956a429fced8 (diff)
downloadcoinosv3-2b83c3f46c0dc2da1bbd9854443d57de54b979ea.tar.gz
coinosv3-2b83c3f46c0dc2da1bbd9854443d57de54b979ea.zip
Feed: your newest post is in Following from the first ask, and a new post goes to the feeds it belongs to. Adam posted from the laptop with the #photography feed open and found the post in #photography (untagged) but not in Following, on either device, until a later refresh. Two causes. The feed's opening ask (prefetchFeed, and seedOtherFeeds) took only the first 400 of its authors, and your own key was added after the follows — with 898 follows it sat in the third chunk, so the opening ask never named you; the later refresh (feedPass, every chunk) did. Your key now leads the author list, and the opening ask covers every author, a chunk per ask. And publishPost put the provisional post at the top of whatever feed was open: now it goes to the feeds it would reach — the open feed and Following when they carry your posts (Following, a people feed with you in it, Everything) or a topic the post wears — swapped for the signed event or withdrawn in each. The hashtags in the text go out as t tags (NIP-24, up to the hashtag-spam count), so topic feeds here and elsewhere find the post. tools/own-post-feeds-test.js (450 follows: every one asked, your key first; a post from Following; an untagged post from a topic feed stays out of it; a tagged one lands in both).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Diffstat (limited to 'src/features/messages.js')
-rw-r--r--src/features/messages.js52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index b1da365..7abbb93 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -5660,12 +5660,16 @@ export function messagesFeature(ctx) {
// posts a wider net found in one six-hour window were theirs.
const FEED_AUTHORS_MAX = 2000;
const REQ_AUTHORS = 400; // authors per REQ, so one filter stays a sane size
+ const authorChunks = (authors) => { const out = []; for (let i = 0; i < authors.length; i += REQ_AUTHORS) out.push(authors.slice(i, i + REQ_AUTHORS)); return out; };
const feedAuthors = (def = feedDef()) => {
if (!def) return [];
- const set = new Set(def.follows ? followsNow().set : []);
// your own posts belong in the feed of the people you follow, as in
- // every other client — not only for the moment after posting
- if (def.follows && mePk()) set.add(mePk());
+ // every other client — not only for the moment after posting. Yours
+ // first: a feed's opening ask takes the authors in chunks of REQ_AUTHORS,
+ // and with 898 follows a key added last sat in the third chunk — the
+ // feed opened without your newest post until a later refresh.
+ const set = new Set(def.follows && mePk() ? [mePk()] : []);
+ if (def.follows) for (const pk of followsNow().set) set.add(pk);
for (const pk of def.authors || []) if (pk) set.add(pk);
for (const pk of def.priv || []) if (pk) set.add(pk); // a list's private members
for (const pk of packAuthors(def)) set.add(pk);
@@ -5852,7 +5856,7 @@ export function messagesFeature(ctx) {
let feedWarmTimer = null, feedWarmSession = 0;
async function prefetchFeed(c) {
const def = feedDef(c.id);
- const authors = feedAuthors(def).slice(0, REQ_AUTHORS), topics = feedTopics(def);
+ const authors = feedAuthors(def), topics = feedTopics(def);
if (!authors.length && !topics.length && !(def && def.all)) { c.status = 'ready'; return; }
c.at = Date.now();
const merge = { newerThan: c.notes.length ? c.notes[0].created_at : Infinity };
@@ -5865,9 +5869,11 @@ export function messagesFeature(ctx) {
try {
const orT = orTopicsOf(def);
await Promise.all([
- // 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),
+ // people's reposts with their posts (a topic or firehose ask: posts only);
+ // every author, a chunk of them per ask
+ ...(authors.length ? authorChunks(authors) : [null]).map((chunk) =>
+ queryFeed(feedRelaysOr(def, def && def.all ? FIREHOSE_RELAYS : NOTE_RELAYS), { kinds: chunk && !topics.length ? [...FEED_KINDS, REPOST] : FEED_KINDS, limit: FEED_PAGE,
+ ...(chunk ? { authors: chunk } : {}), ...(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 {
if (!c.stopped) {
@@ -5903,11 +5909,12 @@ export function messagesFeature(ctx) {
feedsSeededAt = Date.now();
for (const def of feedList()) {
if (def.curated || def.of || feedStates.has(def.id) || disk.has(def.id)) continue;
- const authors = feedAuthors(def).slice(0, REQ_AUTHORS), topics = feedTopics(def);
+ const authors = feedAuthors(def), topics = feedTopics(def);
if (!authors.length && !topics.length) continue;
try {
- const events = await queryOn(feedRelaysOr(def, NOTE_RELAYS), { kinds: FEED_KINDS, limit: FEED_SEED_POSTS * 2,
- ...(authors.length ? { authors } : {}), ...(topics.length ? { '#t': topics } : {}) }, 3000);
+ const events = (await Promise.all((authors.length ? authorChunks(authors) : [null]).map((chunk) =>
+ queryOn(feedRelaysOr(def, NOTE_RELAYS), { kinds: FEED_KINDS, limit: FEED_SEED_POSTS * 2,
+ ...(chunk ? { authors: chunk } : {}), ...(topics.length ? { '#t': topics } : {}) }, 3000)))).flat();
if (feedStates.has(def.id)) continue; // opened while we were asking
disk.seed(def.id, events.filter((e) => FEED_KINDS.includes(e.kind) && !isReply(e) && !hidden(e)));
} catch {}
@@ -10029,17 +10036,26 @@ export function messagesFeature(ctx) {
// and withdrawn on failure.
async function publishPost(text, media = []) {
const id = await requireIdentity();
+ // the hashtags in the text as t tags (NIP-24), so topic feeds and other
+ // clients' searches find the post — up to the count past which a post
+ // reads as hashtag spam
+ const hashtags = [...new Set([...String(text || '').matchAll(/(^|[^\w#/&])#([\p{L}\p{N}_]{2,64})(?![\w])/gu)].map((m) => normTopic(m[2])))].slice(0, HASHTAG_MAX);
const temp = {
id: 'pending:' + Math.random().toString(36).slice(2),
pubkey: id.pubkey, content: text, created_at: Math.floor(Date.now() / 1000),
- tags: [], pending: true,
+ tags: hashtags.map((x) => ['t', x]), pending: true,
};
const caches = [...new Set([id.pubkey, ui.profilePk].filter(Boolean))]
.map((pk) => notesCache.get(pk)).filter(Boolean);
for (const c of caches) c.notes = [temp, ...c.notes];
- // your own post belongs at the top of your own feed too, before any
- // relay has heard of it
- if (feed) { feed.notes = [temp, ...feed.notes]; }
+ // your own post belongs at the top of the feeds it would reach, before
+ // any relay has heard of it: the open feed and Following, when they
+ // carry your posts (Following, a people feed with you in it, Everything)
+ // or a topic the post wears — not a topic feed open at the time that it
+ // doesn't match, where it used to land (and then only there)
+ const carries = (def) => !!def && (!!def.all || feedAuthors(def).includes(id.pubkey) || feedTopics(def).some((x) => hashtags.includes(x)));
+ const feeds = [...new Set([feed, feedStates.get(FOLLOWING)].filter((c) => c && !c.stopped && carries(feedDef(c.id))))];
+ for (const c of feeds) c.notes = [temp, ...c.notes];
render();
try {
// NIP-92: what we uploaded, described, so clients needn't sniff the URL
@@ -10050,19 +10066,17 @@ export function messagesFeature(ctx) {
? [] : ui.quoteOf ? [['q', ui.quoteOf.id], ['p', ui.quoteOf.pubkey]] : [];
// the people it mentions are told (NIP-27 p tags)
const mentions = mentionedPks(text).filter((pk) => pk !== id.pubkey && !q.some((x) => x[0] === 'p' && x[1] === pk)).map((pk) => ['p', pk]);
- const partial = { kind: 1, content: text, created_at: temp.created_at, tags: [...imeta, ...q, ...mentions, CLIENT_TAG] };
+ const partial = { kind: 1, content: text, created_at: temp.created_at, tags: [...imeta, ...q, ...mentions, ...temp.tags, CLIENT_TAG] };
const evt = id.signer instanceof Uint8Array ? finalizeEvent(partial, id.signer) : await id.signer.signEvent(partial);
const relays = [...new Set([...(await notesRelays(id.pubkey)), ...wallet.nostrRelays()])];
const ok = await publishOn(relays, evt);
if (!ok) throw new Error(t('msgSendFailed'));
ui.quoteOf = null;
- for (const c of caches) c.notes = c.notes.map((e) => (e.id === temp.id ? evt : e));
- if (feed) feed.notes = feed.notes.map((e) => (e.id === temp.id ? evt : e));
+ for (const c of [...caches, ...feeds]) c.notes = c.notes.map((e) => (e.id === temp.id ? evt : e));
render();
return evt;
} catch (e) {
- for (const c of caches) c.notes = c.notes.filter((e) => e.id !== temp.id);
- if (feed) feed.notes = feed.notes.filter((e) => e.id !== temp.id);
+ for (const c of [...caches, ...feeds]) c.notes = c.notes.filter((e) => e.id !== temp.id);
render();
throw e;
}