minor fixes
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user