fix ndk
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
import { RelayContext } from "@shared/relayProvider";
|
||||
|
||||
import { READONLY_RELAYS } from "@stores/constants";
|
||||
|
||||
import { getChannel, updateChannelMetadata } from "@utils/storage";
|
||||
|
||||
import { useContext } from "react";
|
||||
import useSWR, { useSWRConfig } from "swr";
|
||||
import useSWRSubscription from "swr/subscription";
|
||||
@@ -18,7 +14,7 @@ const fetcher = async ([, id]) => {
|
||||
};
|
||||
|
||||
export function useChannelProfile(id: string, channelPubkey: string) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const ndk = useContext(RelayContext);
|
||||
|
||||
const { mutate } = useSWRConfig();
|
||||
const { data, isLoading } = useSWR(["channel-metadata", id], fetcher);
|
||||
@@ -27,30 +23,26 @@ export function useChannelProfile(id: string, channelPubkey: string) {
|
||||
!isLoading && data ? ["channel-metadata", id] : null,
|
||||
([, key]) => {
|
||||
// subscribe to channel
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
"#e": [key],
|
||||
authors: [channelPubkey],
|
||||
kinds: [41],
|
||||
},
|
||||
],
|
||||
READONLY_RELAYS,
|
||||
(event: { content: string }) => {
|
||||
// update in local database
|
||||
updateChannelMetadata(key, event.content);
|
||||
// revaildate
|
||||
mutate(["channel-metadata", key]);
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
const sub = ndk.subscribe(
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
"#e": [key],
|
||||
authors: [channelPubkey],
|
||||
kinds: [41],
|
||||
},
|
||||
{
|
||||
closeOnEose: true,
|
||||
},
|
||||
);
|
||||
|
||||
sub.addListener("event", (event: { content: string }) => {
|
||||
// update in local database
|
||||
updateChannelMetadata(key, event.content);
|
||||
// revaildate
|
||||
mutate(["channel-metadata", key]);
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
sub.stop();
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user