Browse Source

Reinstated Notifications

master
silberengel 7 months ago
parent
commit
17fcc15ade
  1. 41
      src/lib/components/EventSearch.svelte

41
src/lib/components/EventSearch.svelte

@ -9,6 +9,7 @@ @@ -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 @@ @@ -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;
// 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;
}
// 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 || "";
// Fetch the actual profile event from relays
const profileEvent = await ndk.fetchEvent({
kinds: [0],
authors: [hexPubkey],
});
handleFoundEvent(profileEvent);
updateSearchState(false, true, 1, "profile");
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();

Loading…
Cancel
Save