-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-user-profile-query.ts
42 lines (40 loc) · 1.03 KB
/
get-user-profile-query.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Kind } from "nostr-tools";
import { useNostrFetchQuery } from "../core";
import { convertEvent } from "../utils/event-converter";
export function useNostrGetUserProfileQuery(pubKey?: string | null) {
return useNostrFetchQuery(
["chats/nostr-get-user-profile", pubKey],
[
{
kinds: [Kind.Metadata],
authors: [pubKey!!],
},
],
(events) =>
events
.map((event) => convertEvent<Kind.Metadata>(event)!!)
.filter((profile) => profile!!),
{
enabled: !!pubKey,
refetchOnMount: false,
},
);
}
export function useNostrGetUserProfilesQuery(pubKeys: string[]) {
return useNostrFetchQuery(
["chats/nostr-get-user-profile", pubKeys],
pubKeys.map((user) => ({
kinds: [Kind.Metadata],
authors: [user],
})),
(events) =>
events
.map((event) => convertEvent<Kind.Metadata>(event)!!)
.filter((profile) => profile!!),
{
initialData: [],
refetchOnMount: false,
enabled: pubKeys.length > 0,
},
);
}