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 @@
import { getNdkContext, activeInboxRelays } from "../ndk.ts"; import { getNdkContext, activeInboxRelays } from "../ndk.ts";
import { get } from "svelte/store"; import { get } from "svelte/store";
import type { NDKEvent } from "@nostr-dev-kit/ndk"; import type { NDKEvent } from "@nostr-dev-kit/ndk";
import type NDK from "@nostr-dev-kit/ndk";
import { userStore } from "../stores/userStore.ts"; import { userStore } from "../stores/userStore.ts";
import { nip19 } from "nostr-tools"; import { nip19 } from "nostr-tools";
import { npubCache } from "./npubCache.ts"; import { npubCache } from "./npubCache.ts";
@ -50,10 +51,11 @@ export interface UserListEvent {
*/ */
export async function fetchUserLists( export async function fetchUserLists(
pubkey: string, pubkey: string,
listKinds: number[] = [...PEOPLE_LIST_KINDS] listKinds: number[] = [...PEOPLE_LIST_KINDS],
ndk?: NDK
): Promise<UserListEvent[]> { ): Promise<UserListEvent[]> {
const ndk = getNdkContext(); const ndkInstance = ndk || getNdkContext();
if (!ndk) { if (!ndkInstance) {
console.warn("fetchUserLists: No NDK instance available"); console.warn("fetchUserLists: No NDK instance available");
return []; return [];
} }
@ -61,7 +63,7 @@ export async function fetchUserLists(
console.log(`fetchUserLists: Fetching lists for ${pubkey}, kinds:`, listKinds); console.log(`fetchUserLists: Fetching lists for ${pubkey}, kinds:`, listKinds);
try { try {
const events = await ndk.fetchEvents({ const events = await ndkInstance.fetchEvents({
kinds: listKinds, kinds: listKinds,
authors: [pubkey], authors: [pubkey],
}); });
@ -120,10 +122,12 @@ export async function fetchUserLists(
/** /**
* Fetch the current user's lists * Fetch the current user's lists
* @param listKinds - Array of list kinds to fetch (defaults to all people list kinds) * @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 * @returns Promise that resolves to an array of UserListEvent objects
*/ */
export async function fetchCurrentUserLists( export async function fetchCurrentUserLists(
listKinds: number[] = [...PEOPLE_LIST_KINDS] listKinds: number[] = [...PEOPLE_LIST_KINDS],
ndk?: NDK
): Promise<UserListEvent[]> { ): Promise<UserListEvent[]> {
const userState = get(userStore); const userState = get(userStore);
@ -133,7 +137,7 @@ export async function fetchCurrentUserLists(
} }
console.log("fetchCurrentUserLists: Found user pubkey:", userState.pubkey); 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 * This ensures follows are always cached and prioritized
* @param pubkeys - Array of pubkeys to cache profiles for * @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; if (pubkeys.length === 0) return;
try { try {
console.log(`Updating profile cache for ${pubkeys.length} pubkeys`); console.log(`Updating profile cache for ${pubkeys.length} pubkeys`);
const ndk = getNdkContext(); const ndkInstance = ndk || getNdkContext();
if (!ndk) { if (!ndkInstance) {
console.warn("updateProfileCacheForPubkeys: No NDK instance available"); console.warn("updateProfileCacheForPubkeys: No NDK instance available");
return; return;
} }
@ -223,7 +227,7 @@ export async function updateProfileCacheForPubkeys(pubkeys: string[]): Promise<v
const batch = pubkeys.slice(i, i + batchSize); const batch = pubkeys.slice(i, i + batchSize);
try { try {
const events = await ndk.fetchEvents({ const events = await ndkInstance.fetchEvents({
kinds: [0], kinds: [0],
authors: batch, authors: batch,
}); });

9
src/routes/events/+page.svelte

@ -13,7 +13,7 @@
import EventInput from "$lib/components/EventInput.svelte"; import EventInput from "$lib/components/EventInput.svelte";
import CopyToClipboard from "$lib/components/util/CopyToClipboard.svelte"; import CopyToClipboard from "$lib/components/util/CopyToClipboard.svelte";
import { neventEncode, naddrEncode } from "$lib/utils"; 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 { getEventType } from "$lib/utils/mime";
import ViewPublicationLink from "$lib/components/util/ViewPublicationLink.svelte"; import ViewPublicationLink from "$lib/components/util/ViewPublicationLink.svelte";
import { checkCommunity } from "$lib/utils/search_utility"; import { checkCommunity } from "$lib/utils/search_utility";
@ -57,6 +57,9 @@
userStore.subscribe((val) => (user = val)); userStore.subscribe((val) => (user = val));
// Get NDK context during component initialization
const ndk = getNdkContext();
// Debug: Check if user is logged in // Debug: Check if user is logged in
$effect(() => { $effect(() => {
console.log("[Events Page] User state:", user); console.log("[Events Page] User state:", user);
@ -80,7 +83,7 @@
// If the event doesn't have user list information, fetch it // If the event doesn't have user list information, fetch it
if (typeof parsedProfile.isInUserLists !== 'boolean') { if (typeof parsedProfile.isInUserLists !== 'boolean') {
fetchCurrentUserLists() fetchCurrentUserLists(undefined, ndk)
.then((userLists) => { .then((userLists) => {
const isInLists = isPubkeyInUserLists(newEvent.pubkey, userLists); const isInLists = isPubkeyInUserLists(newEvent.pubkey, userLists);
// Update the profile with user list information // 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 // AI-NOTE: 2025-01-24 - Function to update profile data with user list information
async function updateProfileDataWithUserLists(events: NDKEvent[]) { async function updateProfileDataWithUserLists(events: NDKEvent[]) {
try { try {
const userLists = await fetchCurrentUserLists(); const userLists = await fetchCurrentUserLists(undefined, ndk);
for (const event of events) { for (const event of events) {
if (event.kind === 0 && event.pubkey) { if (event.kind === 0 && event.pubkey) {

Loading…
Cancel
Save