From b331392a7ea1e3a9e97820e65570c4dc47309166 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 20 Oct 2025 23:03:44 -0400 Subject: [PATCH] Improve subscription relay coverage --- js/subscriptions.js | 66 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/js/subscriptions.js b/js/subscriptions.js index 16114dd6..a7c0e011 100644 --- a/js/subscriptions.js +++ b/js/subscriptions.js @@ -141,24 +141,70 @@ class SubscriptionsManager { return; } try { + const normalizedUserPubkey = normalizeHexPubkey(userPubkey) || userPubkey; + const sessionActorPubkey = normalizeHexPubkey( + nostrClient?.sessionActor?.pubkey, + ); + + const authorSet = new Set(); + if (normalizedUserPubkey) { + authorSet.add(normalizedUserPubkey); + } + if (sessionActorPubkey) { + authorSet.add(sessionActorPubkey); + } + + const authors = Array.from(authorSet); + if (!authors.length && userPubkey) { + authors.push(userPubkey); + } + const filter = { kinds: [30002], - authors: [userPubkey], + authors, "#d": [SUBSCRIPTION_LIST_IDENTIFIER], limit: 1 }; - const relayPromises = []; - for (const url of nostrClient.relays) { - const listPromise = nostrClient.pool - .list([url], [filter]) - .catch((err) => { - userLogger.error(`[SubscriptionsManager] Relay error at ${url}`, err); - throw err; - }); - relayPromises.push(listPromise); + const relaySet = new Set(); + const addRelayCandidates = (candidates) => { + if (!candidates) { + return; + } + const iterable = Array.isArray(candidates) + ? candidates + : candidates instanceof Set + ? Array.from(candidates) + : []; + for (const candidate of iterable) { + if (typeof candidate !== "string") { + continue; + } + const trimmed = candidate.trim(); + if (trimmed) { + relaySet.add(trimmed); + } + } + }; + + addRelayCandidates(nostrClient.readRelays); + addRelayCandidates(nostrClient.relays); + addRelayCandidates(DEFAULT_RELAY_URLS); + + const relayUrls = Array.from(relaySet); + if (!relayUrls.length) { + devLogger.warn( + "[SubscriptionsManager] No relay URLs available while loading subscriptions.", + ); } + const relayPromises = relayUrls.map((url) => + nostrClient.pool.list([url], [filter]).catch((err) => { + userLogger.error(`[SubscriptionsManager] Relay error at ${url}`, err); + return []; + }), + ); + const settledResults = await Promise.allSettled(relayPromises); const events = []; for (const outcome of settledResults) {