minor fixes

This commit is contained in:
Ren Amamiya
2023-04-29 09:25:33 +07:00
parent a1385f87dc
commit be8b40c86d
10 changed files with 70 additions and 66 deletions

View File

@@ -4,49 +4,46 @@ import { RelayPool } from 'nostr-relaypool';
import useSWRSubscription from 'swr/subscription';
export const useChannelProfile = (id: string, channelPubkey: string) => {
const { data } = useSWRSubscription(
id
? [
{
kinds: [41],
'#e': [id],
},
{
ids: [id],
kinds: [40],
},
]
: null,
(key, { next }) => {
const pool = new RelayPool(FULL_RELAYS);
const unsubscribe = pool.subscribe(
key,
FULL_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) {
case 40:
next(null, JSON.parse(event.content));
break;
case 41:
if (event.pubkey === channelPubkey) {
next(null, JSON.parse(event.content));
}
default:
break;
}
},
undefined,
undefined,
const { data } = useSWRSubscription(id ? id : null, (key, { next }) => {
const pool = new RelayPool(FULL_RELAYS);
const unsubscribe = pool.subscribe(
[
{
unsubscribeOnEose: true,
kinds: [41],
'#e': [key],
},
{
ids: [key],
kinds: [40],
},
],
FULL_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) {
case 40:
next(null, JSON.parse(event.content));
break;
case 41:
console.log(event);
if (event.pubkey === channelPubkey) {
next(null, JSON.parse(event.content));
}
break;
default:
break;
}
);
},
undefined,
undefined,
{
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
}
);
return () => {
unsubscribe();
};
});
return data;
};