aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.js2
-rw-r--r--src/features/messages.js44
-rw-r--r--src/i18n.js1
3 files changed, 42 insertions, 5 deletions
diff --git a/src/app.js b/src/app.js
index 95909d0..50aa5c8 100644
--- a/src/app.js
+++ b/src/app.js
@@ -3078,6 +3078,8 @@ function headerSearch() {
type: 'text', class: 'header-search', placeholder: t('searchUsers') + '…', 'aria-label': t('searchUsers'),
value: (ui.userSearch && ui.userSearch.q) || '', autocapitalize: 'none', autocomplete: 'off', spellcheck: 'false',
onInput: (e) => { clearFeatureNavKeepSearch(); featureHook('userSearchQuery', e.target.value); },
+ // Enter without picking a suggestion: full-text search over notes
+ onKeydown: (e) => { if (e.key === 'Enter' && !e.isComposing && e.target.value.trim()) { e.preventDefault(); featureHook('userSearchSubmit', e.target.value); e.target.blur(); } },
});
}
function clearFeatureNavKeepSearch() {
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();
diff --git a/src/i18n.js b/src/i18n.js
index 8f54f1a..d1de016 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -483,6 +483,7 @@ const STR = {
listNew: 'New list…',
profLists: 'Lists',
searchTopicRow: 'Posts on this topic',
+ searchPostsRow: 'Posts and replies that say this',
searchTopicFor: 'Posts tagged #{q}',
relayLinkOpen: 'See what’s posted on this relay',
alertsTitle: 'Notifications',