update thread

This commit is contained in:
Ren Amamiya
2023-06-27 11:42:12 +07:00
parent 2f553d8039
commit 6abff45678
25 changed files with 396 additions and 295 deletions

View File

@@ -1,3 +1,4 @@
import { createReplyNote } from "./storage";
import NDK, {
NDKConstructorParams,
NDKEvent,
@@ -10,12 +11,22 @@ import { FULL_RELAYS } from "@stores/constants";
import { useAccount } from "@utils/hooks/useAccount";
import { useContext } from "react";
export async function initNDK(
relays?: string[],
cache?: boolean,
): Promise<NDK> {
export async function initNDK(relays?: string[]): Promise<NDK> {
const opts: NDKConstructorParams = {};
opts.explicitRelayUrls = relays || FULL_RELAYS;
const defaultRelays = new Set(relays || FULL_RELAYS);
/*
for (const relay of defaultRelays) {
const url = new URL(relay);
url.protocol = url.protocol = url.protocol.replace("wss", "https");
const res = await fetch(url.href, { method: "HEAD", timeout: 5 });
if (!res.ok) {
defaultRelays.delete(relay);
}
}
*/
opts.explicitRelayUrls = [...defaultRelays];
const ndk = new NDK(opts);
await ndk.connect();
@@ -40,7 +51,7 @@ export async function prefetchEvents(
});
relaySetSubscription.on("eose", () => {
setTimeout(() => resolve(new Set(events.values())), 5000);
setTimeout(() => resolve(new Set(events.values())), 3000);
});
});
}
@@ -54,11 +65,15 @@ export function usePublish() {
ndk.signer = signer;
}
function publish({
const publish = ({
content,
kind,
tags,
}: { content: string; kind: NDKKind; tags: string[][] }) {
}: {
content: string;
kind: NDKKind;
tags: string[][];
}): NDKEvent => {
const event = new NDKEvent(ndk);
event.content = content;
@@ -68,7 +83,9 @@ export function usePublish() {
event.tags = tags;
event.publish();
}
return event;
};
return publish;
}