1
0
Fork 0

nip5 handles

This commit is contained in:
Kieran 2023-08-23 14:14:38 +01:00
parent c191a7684a
commit 7cba67e4c1
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 38 additions and 8 deletions

View File

@ -37,8 +37,9 @@ export function useZaps(goal: NostrEvent, leaveOpen = false) {
);
}
export function useZapGoal(host: string, link: NostrLink, leaveOpen = false) {
export function useZapGoal(host: string, link?: NostrLink, leaveOpen = false) {
const sub = useMemo(() => {
if (!link) return null;
const b = new RequestBuilder(`goals:${host.slice(0, 12)}`);
b.withOptions({ leaveOpen });
b.withFilter()

View File

@ -11,7 +11,7 @@ import { RootPage } from "pages/root";
import { TagPage } from "pages/tag";
import { LayoutPage } from "pages/layout";
import { ProfilePage } from "pages/profile-page";
import { StreamPage } from "pages/stream-page";
import { StreamPageHandler } from "pages/stream-page";
import { ChatPopout } from "pages/chat-popout";
import { LoginStore } from "login";
import { StreamProvidersPage } from "pages/providers";
@ -54,7 +54,7 @@ const router = createBrowserRouter([
},
{
path: "/:id",
element: <StreamPage />,
element: <StreamPageHandler />,
},
{
path: "/providers/:id?",

View File

@ -1,6 +1,6 @@
import "./stream-page.css";
import { parseNostrLink, TaggedRawEvent } from "@snort/system";
import { unwrap } from "@snort/shared";
import { NostrLink, NostrPrefix, TaggedRawEvent, tryParseNostrLink } from "@snort/system";
import { fetchNip05Pubkey } from "@snort/shared";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { Helmet } from "react-helmet";
@ -10,6 +10,7 @@ import {
findTag,
getEventFromLocationState,
getHost,
hexToBech32,
} from "utils";
import { Profile, getName } from "element/profile";
import { LiveChat } from "element/live-chat";
@ -32,6 +33,7 @@ import {
isContentWarningAccepted,
} from "element/content-warning";
import { useCurrentStreamFeed } from "hooks/current-stream-feed";
import { useEffect, useState } from "react";
function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) {
const login = useLogin();
@ -111,14 +113,41 @@ function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) {
);
}
export function StreamPage() {
export function StreamPageHandler() {
const params = useParams();
const location = useLocation();
const evPreload = getEventFromLocationState(location.state);
const link = parseNostrLink(unwrap(params.id));
const [link, setLink] = useState<NostrLink>();
useEffect(() => {
if (params.id) {
const parsedLink = tryParseNostrLink(params.id);
if (parsedLink) {
setLink(parsedLink);
} else {
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@");
fetchNip05Pubkey(handle, domain).then(d => {
if (d) {
setLink({
id: d,
type: NostrPrefix.PublicKey,
encode: () => hexToBech32(NostrPrefix.PublicKey, d)
} as NostrLink);
}
})
}
}
}, [params.id]);
if (link) {
return <StreamPage link={link} evPreload={evPreload} />
}
}
export function StreamPage({ link, evPreload }: { evPreload?: NostrEvent, link: NostrLink }) {
const ev = useCurrentStreamFeed(link, true, evPreload);
const host = getHost(ev);
const goal = useZapGoal(host, link, true);
const goal = useZapGoal(host, createNostrLink(ev), true);
const title = findTag(ev, "title");
const summary = findTag(ev, "summary");