From 6d3e24fc71f2f3a000364bd8c2491fcdb1cd99f9 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 6 Feb 2024 12:38:48 +0000 Subject: [PATCH] fix: reliably fetch user profiles - do not get UserRelay list due to ndk bug - wait 200ms to allow for more batching of requests --- src/lib/stores/users.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lib/stores/users.ts b/src/lib/stores/users.ts index 2e9f999..4489b9f 100644 --- a/src/lib/stores/users.ts +++ b/src/lib/stores/users.ts @@ -19,8 +19,14 @@ export const ensureUser = (hexpubkey: string): Writable => { } users[hexpubkey] = writable(base) - getUserRelays(hexpubkey) - u.fetchProfile().then( + // getUserRelays is broken due to NDK bug + // getUserRelays(hexpubkey) + u.fetchProfile({ + closeOnEose: true, + groupable: true, + // default 100 + groupableDelay: 200, + }).then( (p) => { users[hexpubkey].update((u) => ({ ...u, @@ -109,6 +115,7 @@ interface UserRelays { export const user_relays: { [hexpubkey: string]: Writable } = {} +// Do Not Use - NDK has a bug when batching user relay requests export const getUserRelays = async (hexpubkey: string): Promise => { return new Promise(async (res, _) => { if (user_relays[hexpubkey]) { @@ -125,7 +132,11 @@ export const getUserRelays = async (hexpubkey: string): Promise => { loading: true, ndk_relays: undefined, }) - const relay_list = await ndk.getUser({ hexpubkey }).relayList() + const relay_list = await ndk + .getUser({ hexpubkey }) + // when batching requests NDK creates a really long subid, + // beyond the 71 chars that most relays support + .relayList() const querying_user_relays = { loading: false, ndk_relays: relay_list,