From 22235235b31cd97b322ba89e1cfe5e9f42877c54 Mon Sep 17 00:00:00 2001 From: silberengel Date: Sun, 10 Aug 2025 16:08:48 +0200 Subject: [PATCH] got rid of hard-coded relays --- src/lib/components/EventInput.svelte | 5 +-- src/lib/components/Notifications.svelte | 56 +++++++------------------ src/lib/consts.ts | 2 + src/lib/utils/kind24_utils.ts | 7 +--- src/routes/contact/+page.svelte | 10 ++--- 5 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/lib/components/EventInput.svelte b/src/lib/components/EventInput.svelte index 0519692..cec2cde 100644 --- a/src/lib/components/EventInput.svelte +++ b/src/lib/components/EventInput.svelte @@ -29,6 +29,7 @@ import { Button } from "flowbite-svelte"; import { goto } from "$app/navigation"; import { WebSocketPool } from "$lib/data_structures/websocket_pool"; + import { anonymousRelays } from "$lib/consts"; let kind = $state(30040); let tags = $state<[string, string][]>([]); @@ -384,9 +385,7 @@ // Try to publish to relays directly const relays = [ - "wss://relay.damus.io", - "wss://relay.nostr.band", - "wss://nos.lol", + ...anonymousRelays, ...$activeOutboxRelays, ...$activeInboxRelays, ]; diff --git a/src/lib/components/Notifications.svelte b/src/lib/components/Notifications.svelte index e915315..4a98bc3 100644 --- a/src/lib/components/Notifications.svelte +++ b/src/lib/components/Notifications.svelte @@ -10,7 +10,7 @@ import { goto } from "$app/navigation"; import { get } from "svelte/store"; import { nip19 } from "nostr-tools"; - import { communityRelays, localRelays } from "$lib/consts"; + import { communityRelays, localRelays, anonymousRelays, searchRelays } from "$lib/consts"; import { createKind24Reply, getKind24RelaySet } from "$lib/utils/kind24_utils"; import { createSignedEvent } from "$lib/utils/nostrEventService"; import RelayDisplay from "$lib/components/RelayDisplay.svelte"; @@ -191,38 +191,24 @@ return parsedContent; } - function renderQuotedContent(message: NDKEvent): string { + async function renderQuotedContent(message: NDKEvent): Promise { const qTags = message.getMatchingTags("q"); if (qTags.length === 0) return ""; const qTag = qTags[0]; - const nevent = qTag[1]; - - // Extract event ID from nevent - let eventId = ''; - try { - const decoded = nip19.decode(nevent); - if (decoded.type === 'nevent' && decoded.data.id) { - eventId = decoded.data.id; - } - } catch (error) { - // If decode fails, try to extract hex ID directly - const hexMatch = nevent.match(/[a-f0-9]{64}/i); - if (hexMatch) { - eventId = hexMatch[0]; - } - } + const eventId = qTag[1]; if (eventId) { // Find the quoted message in our public messages const quotedMessage = publicMessages.find(msg => msg.id === eventId); if (quotedMessage) { const quotedContent = quotedMessage.content ? quotedMessage.content.slice(0, 200) : "No content"; - return `
${quotedContent}
`; + const parsedContent = await parseBasicmarkup(quotedContent); + return `
${parsedContent}
`; } } - return ""; + return ""; } function getNotificationType(event: NDKEvent): string { @@ -520,9 +506,7 @@ // Add q tag if replying to a message (for jump-to functionality) if (replyToMessage) { - // Get the first relay from newMessageRelays or use a fallback - const relayUrl = newMessageRelays[0] || "wss://freelay.sovbit.host/"; - pTags.push(["q", replyToMessage.id, relayUrl, replyToMessage.pubkey]); + pTags.push(["q", replyToMessage.id, newMessageRelays[0] || anonymousRelays[0]]); } // Get all recipient pubkeys for relay calculation (ensure hex format) @@ -559,14 +543,8 @@ const uniqueRelays = [...new Set(allRelays)]; newMessageRelays = uniqueRelays; - // Create the kind 24 event with quoted content if replying - let finalContent = newMessageContent; - if (replyToMessage && quotedContent) { - // Generate the markdown quote format for the actual message - const neventUrl = getNeventUrl(replyToMessage); - const markdownQuote = `> QUOTED: ${quotedContent} • LINK: ${neventUrl}`; - finalContent = markdownQuote + "\n\n" + newMessageContent; - } + // Use the content as-is, quoted content is handled via q tag + const finalContent = newMessageContent; // Create and sign the event using the unified function (includes expiration tag) const { event: signedEvent } = await createSignedEvent( @@ -649,16 +627,6 @@ } // Try search relays - const searchRelays = [ - "wss://profiles.nostr1.com", - "wss://aggr.nostr.land", - "wss://relay.noswhere.com", - "wss://nostr.wine", - "wss://relay.damus.io", - "wss://relay.nostr.band", - "wss://freelay.sovbit.host" - ]; - for (const relay of searchRelays) { try { const ndk = get(ndkInstance); @@ -1062,7 +1030,11 @@ {#if message.getMatchingTags("q").length > 0}
- {@html renderQuotedContent(message)} + {#await renderQuotedContent(message) then quotedHtml} + {@html quotedHtml} + {:catch} + + {/await}
{/if} {#if message.content} diff --git a/src/lib/consts.ts b/src/lib/consts.ts index f141e7b..b8e7f0d 100644 --- a/src/lib/consts.ts +++ b/src/lib/consts.ts @@ -33,6 +33,8 @@ export const secondaryRelays = [ export const anonymousRelays = [ "wss://freelay.sovbit.host", "wss://thecitadel.nostr1.com", + "wss://relay.damus.io", + "wss://relay.nostr.band" ]; export const lowbandwidthRelays = [ diff --git a/src/lib/utils/kind24_utils.ts b/src/lib/utils/kind24_utils.ts index cb43e57..69c59ed 100644 --- a/src/lib/utils/kind24_utils.ts +++ b/src/lib/utils/kind24_utils.ts @@ -5,6 +5,7 @@ import { NDKEvent, NDKRelaySet, NDKUser } from "@nostr-dev-kit/ndk"; import type NDK from "@nostr-dev-kit/ndk"; import { nip19 } from "nostr-tools"; import { createSignedEvent } from "./nostrEventService.ts"; +import { anonymousRelays } from "../consts"; /** * Fetches user's outbox relays from NIP-65 relay list @@ -161,11 +162,7 @@ export async function createKind24Reply( // Add q tag if replying to an original event if (originalEvent) { - const nevent = nip19.neventEncode({ - id: originalEvent.id, - relays: prioritizedRelays.slice(0, 3) // Use first 3 relays - }); - tags.push(["q", nevent, prioritizedRelays[0]]); + tags.push(["q", originalEvent.id, prioritizedRelays[0] || anonymousRelays[0]]); } // Create and sign the event using the unified function (includes expiration tag) diff --git a/src/routes/contact/+page.svelte b/src/routes/contact/+page.svelte index 4137220..b520ddc 100644 --- a/src/routes/contact/+page.svelte +++ b/src/routes/contact/+page.svelte @@ -11,7 +11,7 @@ } from "flowbite-svelte"; import { ndkInstance, ndkSignedIn, activeInboxRelays, activeOutboxRelays } from "$lib/ndk"; import { userStore } from "$lib/stores/userStore"; - import { communityRelays } from "$lib/consts"; + import { communityRelays, anonymousRelays } from "$lib/consts"; import type NDK from "@nostr-dev-kit/ndk"; import { NDKEvent, NDKRelaySet } from "@nostr-dev-kit/ndk"; // @ts-ignore - Workaround for Svelte component import issue @@ -62,13 +62,11 @@ const repoAddress = "naddr1qvzqqqrhnypzplfq3m5v3u5r0q9f255fdeyz8nyac6lagssx8zy4wugxjs8ajf7pqy88wumn8ghj7mn0wvhxcmmv9uqq5stvv4uxzmnywf5kz2elajr"; - // Use the new relay management system instead of hardcoded relays + // Use the new relay management system with anonymous relays as fallbacks const allRelays = [ - "wss://relay.damus.io", - "wss://relay.nostr.band", - "wss://nos.lol", ...$activeInboxRelays, ...$activeOutboxRelays, + ...anonymousRelays, ]; // Hard-coded repository owner pubkey and ID from the task @@ -213,7 +211,7 @@ ...(ndk.pool ? Array.from(ndk.pool.relays.values()) .filter( - (relay) => relay.url && !relay.url.includes("wss://nos.lol"), + (relay) => relay.url, ) .map((relay) => normalizeRelayUrl(relay.url)) : []),