diff options
Diffstat (limited to 'src/features')
| -rw-r--r-- | src/features/messages.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 6245c60..6572e27 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -5106,6 +5106,18 @@ export function messagesFeature(ctx) { if (ref.kind === LIST_KIND) return { pk: ref.pk, d: ref.d, relays: ref.relays || [], kind: LIST_KIND }; return null; } + // Draftable (mutable.top) links name a pack by its id and only the first + // eight hex of its author: /draftable/d/<id>?p=<prefix>. The id is asked + // for and the author matched by that prefix. + const PACK_INDEX_RELAYS = () => [...new Set([...PACK_RELAYS, 'wss://relay.damus.io', 'wss://nos.lol', 'wss://nostr.oxtr.dev'])]; + async function resolveShortPackLink(input) { + const m = /\/d\/([^/?#\s]+)[^?\s]*\?(?:[^#\s]*&)?p=([0-9a-f]{4,63})(?![0-9a-f])/i.exec(String(input || '')); + if (!m) return null; + const d = decodeURIComponent(m[1]), prefix = m[2].toLowerCase(); + const evs = await queryOn(PACK_INDEX_RELAYS(), { kinds: [PACK_KIND], '#d': [d], limit: 50 }, 5000).catch(() => []); + const ev = evs.filter((e) => e.kind === PACK_KIND && e.pubkey.startsWith(prefix)).sort((a, b) => b.created_at - a.created_at)[0]; + return ev ? { pk: ev.pubkey, d, relays: [] } : null; + } // Every pack the wide relays hold, once per session: the way to find one // by a few letters of its title — NIP-50 search only knows the packs the // search relay happens to carry, and most live on damus / nos.lol. @@ -5113,7 +5125,7 @@ export function messagesFeature(ctx) { function loadPackIndex() { if (packIndex) return packIndex; packIndex = (async () => { - const relays = [...new Set([...PACK_RELAYS, 'wss://relay.damus.io', 'wss://nos.lol'])]; + const relays = PACK_INDEX_RELAYS(); const all = await Promise.all(relays.map((r) => queryOn([r], { kinds: [PACK_KIND], limit: 500 }, 6000).catch(() => []))); const newest = new Map(); for (const ev of all.flat()) { @@ -11694,7 +11706,8 @@ export function messagesFeature(ctx) { const seq = ++packSearchSeq; q = String(q || '').trim(); if (!e || q.length < 2) { if (e) e.packRows = null; render(); return; } - const link = parsePackLink(q); + const link = parsePackLink(q) || await resolveShortPackLink(q); + if (seq !== packSearchSeq) return; let rows = []; if (link) { const got = await fetchPack(link).catch(() => null); |
