From 17fcc15ade5bb438debd16110343e4fd49cf90e7 Mon Sep 17 00:00:00 2001 From: silberengel Date: Wed, 20 Aug 2025 22:42:33 +0200 Subject: [PATCH] Reinstated Notifications --- src/lib/components/EventSearch.svelte | 41 +++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/lib/components/EventSearch.svelte b/src/lib/components/EventSearch.svelte index e06e132..d084b9c 100644 --- a/src/lib/components/EventSearch.svelte +++ b/src/lib/components/EventSearch.svelte @@ -9,6 +9,7 @@ searchNip05, } from "$lib/utils/search_utility"; import { neventEncode, naddrEncode, nprofileEncode } from "$lib/utils"; + import { nip19 } from "nostr-tools"; import { activeInboxRelays, activeOutboxRelays, @@ -122,16 +123,40 @@ const result = await searchProfiles(query, ndk); if (result.profiles && result.profiles.length > 0) { - console.log("EventSearch: Profile found:", result.profiles[0]); + // Get the npub from the profile, or use the original query if profile doesn't have pubkey + let npub = result.profiles[0].pubkey || query; - // Create an NDKEvent from the profile data - const profileEvent = new NDKEvent(ndk); - profileEvent.kind = 0; // Profile event kind - profileEvent.content = JSON.stringify(result.profiles[0]); - profileEvent.pubkey = result.profiles[0].pubkey || ""; + // Convert npub to hex pubkey + let hexPubkey = ""; + try { + if (npub.startsWith('npub')) { + const decoded = nip19.decode(npub); + if (decoded.type === 'npub') { + hexPubkey = decoded.data; + } + } else { + hexPubkey = npub; + } + } catch (error) { + console.warn("Failed to decode npub to hex:", error); + cleanupSearch(); + updateSearchState(false, true, 0, "profile"); + return; + } - handleFoundEvent(profileEvent); - updateSearchState(false, true, 1, "profile"); + // Fetch the actual profile event from relays + const profileEvent = await ndk.fetchEvent({ + kinds: [0], + authors: [hexPubkey], + }); + + if (profileEvent) { + handleFoundEvent(profileEvent); + updateSearchState(false, true, 1, "profile"); + } else { + cleanupSearch(); + updateSearchState(false, true, 0, "profile"); + } } else { console.log("EventSearch: No profile found for:", query); cleanupSearch();