|
|
|
@ -8,7 +8,6 @@ import { |
|
|
|
} from "../consts.ts"; |
|
|
|
} from "../consts.ts"; |
|
|
|
import { getRelaySetForNetworkCondition } from "./network_detection.ts"; |
|
|
|
import { getRelaySetForNetworkCondition } from "./network_detection.ts"; |
|
|
|
import { networkCondition } from "../stores/networkStore.ts"; |
|
|
|
import { networkCondition } from "../stores/networkStore.ts"; |
|
|
|
import { includeLocalhostRelays } from "../stores/userStore.ts"; |
|
|
|
|
|
|
|
import { get } from "svelte/store"; |
|
|
|
import { get } from "svelte/store"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -350,23 +349,6 @@ async function testLocalRelays( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AI-NOTE: 2025-01-24 - Cache invalidation for localhost preference changes
|
|
|
|
|
|
|
|
// This allows the relay management system to react to user preference changes
|
|
|
|
|
|
|
|
let localhostPreferenceChangeCallback: (() => void) | null = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function setLocalhostPreferenceChangeCallback(callback: () => void) { |
|
|
|
|
|
|
|
localhostPreferenceChangeCallback = callback; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Subscribe to localhost preference changes and trigger relay updates
|
|
|
|
|
|
|
|
if (typeof window !== "undefined") { |
|
|
|
|
|
|
|
includeLocalhostRelays.subscribe(() => { |
|
|
|
|
|
|
|
if (localhostPreferenceChangeCallback) { |
|
|
|
|
|
|
|
localhostPreferenceChangeCallback(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Discovers local relays by testing common localhost URLs |
|
|
|
* Discovers local relays by testing common localhost URLs |
|
|
|
* @param ndk NDK instance |
|
|
|
* @param ndk NDK instance |
|
|
|
@ -374,13 +356,6 @@ if (typeof window !== "undefined") { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export async function discoverLocalRelays(ndk: NDK): Promise<string[]> { |
|
|
|
export async function discoverLocalRelays(ndk: NDK): Promise<string[]> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Check if user has disabled localhost relays
|
|
|
|
|
|
|
|
const shouldIncludeLocalhost = get(includeLocalhostRelays); |
|
|
|
|
|
|
|
if (!shouldIncludeLocalhost) { |
|
|
|
|
|
|
|
console.debug("[relay_management.ts] Localhost relays disabled by user preference"); |
|
|
|
|
|
|
|
return []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If no local relays are configured, return empty array
|
|
|
|
// If no local relays are configured, return empty array
|
|
|
|
if (localRelays.length === 0) { |
|
|
|
if (localRelays.length === 0) { |
|
|
|
console.debug("[relay_management.ts] No local relays configured"); |
|
|
|
console.debug("[relay_management.ts] No local relays configured"); |
|
|
|
@ -711,8 +686,7 @@ export async function buildCompleteRelaySet( |
|
|
|
user?.pubkey || "null", |
|
|
|
user?.pubkey || "null", |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// AI-NOTE: 2025-01-24 - Local relay discovery respects user preference
|
|
|
|
// Discover local relays first
|
|
|
|
// The discoverLocalRelays function will return empty array if user has disabled localhost relays
|
|
|
|
|
|
|
|
const discoveredLocalRelays = await discoverLocalRelays(ndk); |
|
|
|
const discoveredLocalRelays = await discoverLocalRelays(ndk); |
|
|
|
console.debug( |
|
|
|
console.debug( |
|
|
|
"[relay_management.ts] buildCompleteRelaySet: Discovered local relays:", |
|
|
|
"[relay_management.ts] buildCompleteRelaySet: Discovered local relays:", |
|
|
|
|