From 83700027621d9a05f4576196a6d485cd60ac4a46 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Thu, 16 Mar 2023 16:07:58 +0200 Subject: [PATCH] only show popular relays that you are not already connected to --- src/js/nostr/Relays.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/nostr/Relays.ts b/src/js/nostr/Relays.ts index 4b07f1ec..55e1c1d0 100644 --- a/src/js/nostr/Relays.ts +++ b/src/js/nostr/Relays.ts @@ -86,7 +86,7 @@ export default { const content = JSON.parse(event.content); for (const url in content) { try { - const parsed = new URL(url).toString(); + const parsed = new URL(url).toString().replace(/\/$/, ''); const count = relays.get(parsed) || 0; relays.set(parsed, count + 1); } catch (e) { @@ -98,7 +98,9 @@ export default { } } }); - const sorted = Array.from(relays.entries()).sort((a, b) => b[1] - a[1]); + const sorted = Array.from(relays.entries()) + .filter(([url]) => !this.relays.has(url)) + .sort((a, b) => b[1] - a[1]); return sorted.map((entry) => { return { url: entry[0], users: entry[1] }; });