@npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft

Using #NDK is there an easier/more performant way to grab a user's name when you fetch an event than this:

async function fetchEvent(filter) {

const event = await ndk.fetchEvent(filter);

const user = ndk.getUser({ hexpubkey: event.pubkey });

await user.fetchProfile();

return { event: event, user: user.profile };

}

Reply to this note

Please Login to reply.

Discussion

#[1]​ for some reason, primal didn’t tag you on my original post.

not really, because you are really fetching two things; you need to fetch the event that you want and then the profile for that event

we could probably add some syntax sugar to do something like

const event = await ndk.fetchEvent(filter);

const user = event.author();

await user.fetchProfile();

return { event: event, user: user.profile };

I'm not satisfied with the way the profile fetching interface looks like; I'll probably refactor it to something nicer

Awesome. Thank you so much. I’m not really a developer so I wasn’t sure if I was doing something wrong. 😂