Browse Source

got t: searches working again

master
silberengel 7 months ago
parent
commit
e73d20f4d6
  1. 24
      src/lib/utils/user_lists.ts
  2. 9
      src/routes/events/+page.svelte

24
src/lib/utils/user_lists.ts

@ -1,6 +1,7 @@ @@ -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 { @@ -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<UserListEvent[]> {
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( @@ -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( @@ -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<UserListEvent[]> {
const userState = get(userStore);
@ -133,7 +137,7 @@ export async function fetchCurrentUserLists( @@ -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[] @@ -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<void> {
export async function updateProfileCacheForPubkeys(pubkeys: string[], ndk?: NDK): Promise<void> {
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<v @@ -223,7 +227,7 @@ export async function updateProfileCacheForPubkeys(pubkeys: string[]): Promise<v
const batch = pubkeys.slice(i, i + batchSize);
try {
const events = await ndk.fetchEvents({
const events = await ndkInstance.fetchEvents({
kinds: [0],
authors: batch,
});

9
src/routes/events/+page.svelte

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
import EventInput from "$lib/components/EventInput.svelte";
import CopyToClipboard from "$lib/components/util/CopyToClipboard.svelte";
import { neventEncode, naddrEncode } from "$lib/utils";
import { activeInboxRelays, activeOutboxRelays } from "$lib/ndk";
import { activeInboxRelays, activeOutboxRelays, getNdkContext } from "$lib/ndk";
import { getEventType } from "$lib/utils/mime";
import ViewPublicationLink from "$lib/components/util/ViewPublicationLink.svelte";
import { checkCommunity } from "$lib/utils/search_utility";
@ -57,6 +57,9 @@ @@ -57,6 +57,9 @@
userStore.subscribe((val) => (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 @@ @@ -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 @@ @@ -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) {

Loading…
Cancel
Save