From f3d61ac15c832046069bbe0fdf726eea37f89f46 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Fri, 10 Oct 2025 18:09:59 +0200 Subject: [PATCH] only displayed not-yet tried relays in the opt-in list --- src/pages/secondary/NotePage/NotFound.tsx | 24 +++++++++++------- src/services/client.service.ts | 31 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/pages/secondary/NotePage/NotFound.tsx b/src/pages/secondary/NotePage/NotFound.tsx index afbd516..e352690 100644 --- a/src/pages/secondary/NotePage/NotFound.tsx +++ b/src/pages/secondary/NotePage/NotFound.tsx @@ -18,12 +18,15 @@ export default function NotFound({ const [triedExternal, setTriedExternal] = useState(false) const [externalRelays, setExternalRelays] = useState([]) - // Calculate which external relays would be tried + // Calculate which external relays would be tried (excluding already-tried relays) useEffect(() => { if (!bech32Id) return const getExternalRelays = async () => { - const relays: string[] = [] + // Get all relays that would be tried in tiers 1-3 (already tried) + const alreadyTriedRelays = await client.getAlreadyTriedRelays(bech32Id) + + const externalRelays: string[] = [] // Parse relay hints and author from bech32 ID if (!/^[0-9a-f]{64}$/.test(bech32Id)) { @@ -31,15 +34,15 @@ export default function NotFound({ const { type, data } = nip19.decode(bech32Id) if (type === 'nevent') { - if (data.relays) relays.push(...data.relays) + if (data.relays) externalRelays.push(...data.relays) if (data.author) { const authorRelayList = await client.fetchRelayList(data.author) - relays.push(...authorRelayList.write.slice(0, 6)) + externalRelays.push(...authorRelayList.write.slice(0, 6)) } } else if (type === 'naddr') { - if (data.relays) relays.push(...data.relays) + if (data.relays) externalRelays.push(...data.relays) const authorRelayList = await client.fetchRelayList(data.pubkey) - relays.push(...authorRelayList.write.slice(0, 6)) + externalRelays.push(...authorRelayList.write.slice(0, 6)) } } catch (err) { console.error('Failed to parse external relays:', err) @@ -47,9 +50,12 @@ export default function NotFound({ } const seenOn = client.getSeenEventRelayUrls(bech32Id) - relays.push(...seenOn) + externalRelays.push(...seenOn) + + // Filter out relays that were already tried in tiers 1-3 + const newRelays = externalRelays.filter(relay => !alreadyTriedRelays.includes(relay)) - setExternalRelays(Array.from(new Set(relays))) + setExternalRelays(Array.from(new Set(newRelays))) } getExternalRelays() @@ -99,7 +105,7 @@ export default function NotFound({ ) : ( <> - {t('Try searching author\'s relays')} + {t('Try external relays')} )} diff --git a/src/services/client.service.ts b/src/services/client.service.ts index ae3402d..62b73a1 100644 --- a/src/services/client.service.ts +++ b/src/services/client.service.ts @@ -1032,6 +1032,37 @@ class ClientService extends EventTarget { return undefined } + /** + * Get list of relays that were already tried in tiers 1-3 + */ + async getAlreadyTriedRelays(_id: string): Promise { + const userRelayList = this.pubkey ? await this.fetchRelayList(this.pubkey) : { read: [], write: [] } + + // Tier 1: User's read relays + fast read relays + const tier1Relays = Array.from(new Set([ + ...userRelayList.read, + ...FAST_READ_RELAY_URLS + ])) + + // Tier 2: User's write relays + fast write relays + const tier2Relays = Array.from(new Set([ + ...userRelayList.write, + ...FAST_WRITE_RELAY_URLS + ])) + + // Tier 3: Search relays + big relays + const tier3Relays = Array.from(new Set([ + ...SEARCHABLE_RELAY_URLS, + ...BIG_RELAY_URLS + ])) + + return Array.from(new Set([ + ...tier1Relays, + ...tier2Relays, + ...tier3Relays + ])) + } + // Opt-in method to fetch from author's relays, relay hints, and "seen on" relays async fetchEventWithExternalRelays(id: string): Promise { // Clear cache to force new fetch