aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-11 21:35:38 -0700
committerAdam Soltys <[email protected]>2026-11-11 21:35:38 -0700
commitc7455ec7416fb39d4c57e92f5094cc3368b0edfb (patch)
tree8e4a994a5522f3ee850044d7099e48eba77ac258 /src/features
parent0f2407e0fcf0c8267262275367f5bd01edd94532 (diff)
downloadcoinosv3-c7455ec7416fb39d4c57e92f5094cc3368b0edfb.tar.gz
coinosv3-c7455ec7416fb39d4c57e92f5094cc3368b0edfb.zip
Search: Enter on typed words (no suggestion picked) opens a feed of the notes and replies that say them. "if i submit just a string without selecting one of the suggestions i'd like it to do full text search on kind 1 posts and replies. so if i search fiatjaf i should find posts that are mentioning him without necessarily tagging him" (Adam, 2026-11-11). A session feed with def.search asks NIP-50 relays ({ kinds: [1], search }) — relay.ditto.pub, search.nos.today, nostr.wine, the three that answered a kind-1 search probe (nostr.band and primal answered nothing) — keeps replies as rows of their own, pages back with until, and has no live subscription. Enter in the search page's field or the desktop header field opens it, and the search page lists a “words” row ("Posts and replies that say this") above the topic and people rows. Its address is /feed?q=… so it can be shared. tools/post-search-test.js answers the search relays in the page
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6UKGJyuGyZFxddYRxS
Diffstat (limited to 'src/features')
-rw-r--r--src/features/messages.js44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 005b20d..3ed1fa7 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -5200,8 +5200,10 @@ export function messagesFeature(ctx) {
// Threads"): the replies these people write, each under the post it
// answers, instead of their posts. Asked for as notes and NIP-22 comments;
// reposts have no place in it. (REPLY_KINDS, above: a note or a comment.)
- const feedKinds = (def) => (def && def.replies ? REPLY_KINDS : FEED_KINDS);
- const feedKeeps = (def, e) => (def && def.replies ? replyish(e) : FEED_KINDS.includes(e.kind) && !isReply(e));
+ // A word search (def.search) asks NIP-50 relays for notes and replies
+ // whose text holds it: kind 1 only, replies kept as rows of their own.
+ const feedKinds = (def) => (def && def.search ? [1] : def && def.replies ? REPLY_KINDS : FEED_KINDS);
+ const feedKeeps = (def, e) => (def && def.search ? e.kind === 1 : def && def.replies ? replyish(e) : FEED_KINDS.includes(e.kind) && !isReply(e));
// What a reply answers: the e tag marked 'reply' (NIP-10), else 'root'
// (a reply straight to the root), else — the deprecated positional form —
// the last e tag; a NIP-22 comment's lowercase e (its parent), else its E.
@@ -5925,13 +5927,16 @@ export function messagesFeature(ctx) {
// posts from anyone on these tags, as well as the feed's people (Everything)
const orTopicsOf = (def) => [...new Set(((def && def.orTopics) || []).map(normTopic).filter(Boolean))];
const feedTopics = (def = feedDef()) => [...new Set(((def && def.topics) || []).map(normTopic).filter(Boolean))].slice(0, 20);
- const feedHasQuery = (def = feedDef()) => !!def && (!!def.all || feedAuthors(def).length > 0 || feedTopics(def).length > 0);
+ const feedHasQuery = (def = feedDef()) => !!def && (!!def.all || !!def.search || feedAuthors(def).length > 0 || feedTopics(def).length > 0);
// A feed's own relay list, when it has one, replaces the usual choice
// (the authors' outboxes, or the wide relays for a topic) everywhere the
// feed reads. Independent of what the feed asks for.
// Popular relays that answer a bare "everything" query (probed 2026-09-27;
// paid/search relays like nostr.wine and nostr.band answer nothing and are
// left out). The firehose reads a few of them by default.
+ // NIP-50 full-text search over notes (probed 2026-11-11: these three
+ // answer `search` on kind 1; nostr.band and primal answered nothing).
+ const TEXT_SEARCH_RELAYS = ['wss://relay.ditto.pub', 'wss://search.nos.today', 'wss://nostr.wine'];
const RELAY_PICKS = ['wss://relay.coinos.io', 'wss://relay.ditto.pub', 'wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.primal.net', 'wss://relay.snort.social',
'wss://nostr.mom', 'wss://nostr.bitcoiner.social', 'wss://eden.nostr.land', 'wss://nostr.land', 'wss://nostr.oxtr.dev',
'wss://relay.nostrplebs.com', 'wss://offchain.pub', 'wss://nostr21.com', 'wss://relay.nostr.net', 'wss://nostr-pub.wellorder.net'];
@@ -6451,9 +6456,15 @@ export function messagesFeature(ctx) {
async function prefetchFeed(c) {
const def = feedDef(c.id);
const authors = feedAuthors(def), topics = feedTopics(def);
- if (!authors.length && !topics.length && !(def && def.all)) { c.status = 'ready'; return; }
+ if (!authors.length && !topics.length && !(def && (def.all || def.search))) { c.status = 'ready'; return; }
c.at = Date.now();
const merge = { newerThan: c.notes.length ? c.notes[0].created_at : Infinity };
+ if (def.search) {
+ try { await queryFeed(feedRelaysOr(def, TEXT_SEARCH_RELAYS), { kinds: [1], search: def.search, limit: FEED_PAGE }, merge, c, 5000); } catch {} finally {
+ if (!c.stopped) { c.status = 'ready'; if (c === feed && ui.chatOpen && ui.msgView === 'feed') scheduleRepaint(); }
+ }
+ return;
+ }
if (def && def.curated) {
try { await popularPass({}, merge, c, def); } catch {} finally {
if (!c.stopped) { c.status = 'ready'; if (c === feed && ui.chatOpen && ui.msgView === 'feed') { scheduleRepaint(); watchFeed(); } }
@@ -6602,6 +6613,8 @@ export function messagesFeature(ctx) {
const topics = [...new Set((q.get('t') || '').split(',').map(normTopic).filter(Boolean))];
const packs = (q.get('pack') || '').split(',').map((x) => parsePackLink(x.trim())).filter(Boolean);
const relays = urlRelays(q);
+ const words = (q.get('q') || '').trim();
+ if (words) { openTextSearch(words, relays); return true; }
if (!authors.length && !topics.length && !packs.length) { openFirehose(relays); return true; }
const sig = JSON.stringify([authors, topics, packs.map(packKey), relays]);
let hsh = 5381; for (let i = 0; i < sig.length; i++) hsh = ((hsh * 33) ^ sig.charCodeAt(i)) >>> 0;
@@ -6632,6 +6645,7 @@ export function messagesFeature(ctx) {
if (def.all) return (def.curated ? '/feed' : '/feed/all') + r;
if (def.builtin) return share && mePk() && !def.replies ? '/feed/' + npubOf(mePk()) + r : null;
if (def.of) return '/feed/' + npubOf(def.of) + r;
+ if (def.search) return '/feed?q=' + encodeURIComponent(def.search) + (r ? '&' + r.slice(1) : '');
const authors = def.authors || [], topics = feedTopics(def), packs = def.packs || [];
if (!authors.length && !packs.length && topics.length === 1) return '/feed/t/' + encodeURIComponent(topics[0]) + r;
if (!authors.length && !topics.length && packs.length === 1) {
@@ -6759,6 +6773,15 @@ export function messagesFeature(ctx) {
ui.chatOpen = true; ui.msgView = 'feed';
switchFeed(id);
}
+ // Words typed into search and submitted without picking a suggestion:
+ // the notes and replies that say them, as a feed for this session.
+ function openTextSearch(q, relays = []) {
+ q = String(q || '').replace(/\s+/g, ' ').trim().slice(0, 200);
+ if (!q) return;
+ const id = 'search:' + q.toLowerCase() + (relays.length ? '@' + relays.join(',') : '');
+ if (!adhocFeeds.has(id)) adhocFeeds.set(id, { id, name: '\u201c' + q + '\u201d', follows: false, authors: [], packs: [], topics: [], search: q, relays });
+ showFeed(id);
+ }
// Something above the posts is in use — a post being written, the relay
// panel, a focused field — so new posts wait behind the pill rather than
// push it off the screen.
@@ -7789,6 +7812,7 @@ export function messagesFeature(ctx) {
const tag = topics.length ? { '#t': topics } : {};
let got = false;
if (def.curated) return popularPass(extra, merge, c, def);
+ if (def.search) return queryFeed(relays || feedRelaysOr(def, TEXT_SEARCH_RELAYS), { kinds: [1], search: def.search, limit, ...extra }, merge, c);
const orT = orTopicsOf(def);
const orPass = orT.length
? queryFeed(relays || feedRelaysOr(def, TOPIC_RELAYS), { kinds, '#t': orT, limit, ...extra }, merge, c).then((x) => { if (x) got = true; })
@@ -8018,7 +8042,7 @@ export function messagesFeature(ctx) {
function watchFeed() {
const c = feedNow();
const def = feedDef(c.id); // the Conversations view has its own
- if (!feedHasQuery(def) || !ui.chatOpen || ui.msgView !== 'feed') { stopFeedWatch(); return; }
+ if (!feedHasQuery(def) || def.search || !ui.chatOpen || ui.msgView !== 'feed') { stopFeedWatch(); return; }
const newerThan = c.notes.length ? c.notes[0].created_at : Infinity;
const since = Math.floor(Date.now() / 1000) - 60;
const topics = feedTopics(def), tag = topics.length ? { '#t': topics } : {};
@@ -17016,7 +17040,16 @@ export function messagesFeature(ctx) {
type: 'text', class: 'user-search-input user-search-main', placeholder: t('searchUsersHint'), value: s.q,
autocapitalize: 'none', autocomplete: 'off', spellcheck: 'false',
onInput: (e) => { s.q = e.target.value; userSearcher.update(s.q); },
+ onKeydown: (e) => { if (e.key === 'Enter' && !e.isComposing && s.q.trim()) { e.preventDefault(); openTextSearch(s.q); render(); } },
}),
+ // the words themselves: every note and reply that says them
+ s.q.trim().length >= 2 && !/^(npub1|nprofile1|nevent1|note1|naddr1|nostr:)/i.test(s.q.trim())
+ ? h('div', { class: 'list' }, h('div', { class: 'item chat-thread-row', onClick: () => { openTextSearch(s.q); render(); } },
+ h('div', { class: 'chat-avatar fallback' }, '\u{1F50D}'),
+ h('div', { class: 'col grow', style: 'min-width:0;gap:1px' },
+ h('span', { class: 'chat-name' }, '\u201c' + s.q.trim() + '\u201d'),
+ h('div', { class: 'muted small' }, t('searchPostsRow')))))
+ : null,
// a word is a topic too: posts tagged with it, as a feed
(() => {
const m = /^#?([A-Za-z0-9_\u00C0-\uFFFF]{2,64})$/.exec(s.q.trim());
@@ -19008,6 +19041,7 @@ export function messagesFeature(ctx) {
// The header magnifier: search anyone on nostr, results open profiles.
userSearchAvailable() { return true; },
// the desktop header's search field: typing there IS the search page's query
+ userSearchSubmit(q) { if (String(q || '').trim()) { openTextSearch(q); render(); } },
userSearchQuery(q) {
if (!ui.userSearch) { if (!isVisitor()) ui.chatOpen = false; ui.profilePk = null; ui.noteThread = null; ui.liveStream = null; ui.goLive = null; ui.userSearch = { q: '', rows: null }; warmSearch(); }
ui.userSearch.q = q; userSearcher.update(q); render();