From e73d20f4d6537fc5a3ffd5bf471717e4d0b902fd Mon Sep 17 00:00:00 2001 From: silberengel Date: Tue, 19 Aug 2025 16:18:09 +0200 Subject: [PATCH] got t: searches working again --- src/lib/utils/user_lists.ts | 24 ++++++++++++++---------- src/routes/events/+page.svelte | 9 ++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/lib/utils/user_lists.ts b/src/lib/utils/user_lists.ts index e9d7443..dc71be9 100644 --- a/src/lib/utils/user_lists.ts +++ b/src/lib/utils/user_lists.ts @@ -1,6 +1,7 @@ import { getNdkContext, activeInboxRelays } from "../ndk.ts"; import { get } from "svelte/store"; import type { NDKEvent } from "@nostr-dev-kit/ndk"; +import type NDK from "@nostr-dev-kit/ndk"; import { userStore } from "../stores/userStore.ts"; import { nip19 } from "nostr-tools"; import { npubCache } from "./npubCache.ts"; @@ -50,10 +51,11 @@ export interface UserListEvent { */ export async function fetchUserLists( pubkey: string, - listKinds: number[] = [...PEOPLE_LIST_KINDS] + listKinds: number[] = [...PEOPLE_LIST_KINDS], + ndk?: NDK ): Promise { - const ndk = getNdkContext(); - if (!ndk) { + const ndkInstance = ndk || getNdkContext(); + if (!ndkInstance) { console.warn("fetchUserLists: No NDK instance available"); return []; } @@ -61,7 +63,7 @@ export async function fetchUserLists( console.log(`fetchUserLists: Fetching lists for ${pubkey}, kinds:`, listKinds); try { - const events = await ndk.fetchEvents({ + const events = await ndkInstance.fetchEvents({ kinds: listKinds, authors: [pubkey], }); @@ -120,10 +122,12 @@ export async function fetchUserLists( /** * Fetch the current user's lists * @param listKinds - Array of list kinds to fetch (defaults to all people list kinds) + * @param ndk - Optional NDK instance (if not provided, will use getNdkContext) * @returns Promise that resolves to an array of UserListEvent objects */ export async function fetchCurrentUserLists( - listKinds: number[] = [...PEOPLE_LIST_KINDS] + listKinds: number[] = [...PEOPLE_LIST_KINDS], + ndk?: NDK ): Promise { const userState = get(userStore); @@ -133,7 +137,7 @@ export async function fetchCurrentUserLists( } console.log("fetchCurrentUserLists: Found user pubkey:", userState.pubkey); - return fetchUserLists(userState.pubkey, listKinds); + return fetchUserLists(userState.pubkey, listKinds, ndk); } /** @@ -205,14 +209,14 @@ export function getListKindsForPubkey(pubkey: string, userLists: UserListEvent[] * This ensures follows are always cached and prioritized * @param pubkeys - Array of pubkeys to cache profiles for */ -export async function updateProfileCacheForPubkeys(pubkeys: string[]): Promise { +export async function updateProfileCacheForPubkeys(pubkeys: string[], ndk?: NDK): Promise { if (pubkeys.length === 0) return; try { console.log(`Updating profile cache for ${pubkeys.length} pubkeys`); - const ndk = getNdkContext(); - if (!ndk) { + const ndkInstance = ndk || getNdkContext(); + if (!ndkInstance) { console.warn("updateProfileCacheForPubkeys: No NDK instance available"); return; } @@ -223,7 +227,7 @@ export async function updateProfileCacheForPubkeys(pubkeys: string[]): Promise (user = val)); + // Get NDK context during component initialization + const ndk = getNdkContext(); + // Debug: Check if user is logged in $effect(() => { console.log("[Events Page] User state:", user); @@ -80,7 +83,7 @@ // If the event doesn't have user list information, fetch it if (typeof parsedProfile.isInUserLists !== 'boolean') { - fetchCurrentUserLists() + fetchCurrentUserLists(undefined, ndk) .then((userLists) => { const isInLists = isPubkeyInUserLists(newEvent.pubkey, userLists); // Update the profile with user list information @@ -142,7 +145,7 @@ // AI-NOTE: 2025-01-24 - Function to update profile data with user list information async function updateProfileDataWithUserLists(events: NDKEvent[]) { try { - const userLists = await fetchCurrentUserLists(); + const userLists = await fetchCurrentUserLists(undefined, ndk); for (const event of events) { if (event.kind === 0 && event.pubkey) {