feat: zapstr previews
This commit is contained in:
parent
6344a4356a
commit
ed6461fbc8
@ -5,6 +5,7 @@ import Mention from "Element/Mention";
|
|||||||
import NostrFileHeader from "Element/NostrFileHeader";
|
import NostrFileHeader from "Element/NostrFileHeader";
|
||||||
import { parseNostrLink } from "Util";
|
import { parseNostrLink } from "Util";
|
||||||
import NoteQuote from "Element/NoteQuote";
|
import NoteQuote from "Element/NoteQuote";
|
||||||
|
import ZapstrEmbed from "Element/ZapstrEmbed";
|
||||||
|
|
||||||
export default function NostrLink({ link, depth }: { link: string; depth?: number }) {
|
export default function NostrLink({ link, depth }: { link: string; depth?: number }) {
|
||||||
const nav = parseNostrLink(link);
|
const nav = parseNostrLink(link);
|
||||||
@ -15,6 +16,10 @@ export default function NostrLink({ link, depth }: { link: string; depth?: numbe
|
|||||||
if (nav.kind === EventKind.FileHeader) {
|
if (nav.kind === EventKind.FileHeader) {
|
||||||
return <NostrFileHeader link={nav} />;
|
return <NostrFileHeader link={nav} />;
|
||||||
}
|
}
|
||||||
|
if (nav.kind === 31337) {
|
||||||
|
return <ZapstrEmbed link={nav} />;
|
||||||
|
}
|
||||||
|
|
||||||
if ((depth ?? 0) > 0) {
|
if ((depth ?? 0) > 0) {
|
||||||
const evLink = nav.encode();
|
const evLink = nav.encode();
|
||||||
return (
|
return (
|
||||||
|
11
packages/app/src/Element/ZapstrEmbed.tsx
Normal file
11
packages/app/src/Element/ZapstrEmbed.tsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import useEventFeed from "Feed/EventFeed";
|
||||||
|
import Spinner from "Icons/Spinner";
|
||||||
|
import { NostrLink } from "Util";
|
||||||
|
import Text from "./Text";
|
||||||
|
|
||||||
|
export default function ZapstrEmbed({ link }: { link: NostrLink }) {
|
||||||
|
const ev = useEventFeed(link);
|
||||||
|
|
||||||
|
if (!ev.data) return <Spinner />;
|
||||||
|
return <Text content={ev.data.content ?? ""} tags={[]} creator={ev.data.pubkey} />;
|
||||||
|
}
|
@ -1,13 +1,24 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import { NostrPrefix } from "@snort/nostr";
|
||||||
|
|
||||||
import useRequestBuilder from "Hooks/useRequestBuilder";
|
import useRequestBuilder from "Hooks/useRequestBuilder";
|
||||||
import { RequestBuilder, ReplaceableNoteStore } from "System";
|
import { RequestBuilder, ReplaceableNoteStore } from "System";
|
||||||
import { NostrLink } from "Util";
|
import { NostrLink, unwrap } from "Util";
|
||||||
|
|
||||||
export default function useEventFeed(link: NostrLink) {
|
export default function useEventFeed(link: NostrLink) {
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
const b = new RequestBuilder(`event:${link.id.slice(0, 12)}`);
|
const b = new RequestBuilder(`event:${link.id.slice(0, 12)}`);
|
||||||
b.withFilter().id(link.id, link.relays?.at(0));
|
if (link.type === NostrPrefix.Address) {
|
||||||
|
const f = b.withFilter().tag("d", [link.id]);
|
||||||
|
if (link.author) {
|
||||||
|
f.authors([unwrap(link.author)]);
|
||||||
|
}
|
||||||
|
if (link.kind) {
|
||||||
|
f.kinds([unwrap(link.kind)]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b.withFilter().id(link.id, link.relays?.at(0));
|
||||||
|
}
|
||||||
return b;
|
return b;
|
||||||
}, [link]);
|
}, [link]);
|
||||||
|
|
||||||
|
@ -61,16 +61,22 @@ export function decodeTLV(str: string) {
|
|||||||
entries.push({
|
entries.push({
|
||||||
type: t,
|
type: t,
|
||||||
length: l,
|
length: l,
|
||||||
value: decodeTLVEntry(t, new Uint8Array(v)),
|
value: decodeTLVEntry(t, decoded.prefix, new Uint8Array(v)),
|
||||||
});
|
});
|
||||||
x += 2 + l;
|
x += 2 + l;
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeTLVEntry(type: TLVEntryType, data: Uint8Array) {
|
function decodeTLVEntry(type: TLVEntryType, prefix: string, data: Uint8Array) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TLVEntryType.Special:
|
case TLVEntryType.Special: {
|
||||||
|
if (prefix === NostrPrefix.Address) {
|
||||||
|
return new TextDecoder("ASCII").decode(data);
|
||||||
|
} else {
|
||||||
|
return secp.utils.bytesToHex(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
case TLVEntryType.Author: {
|
case TLVEntryType.Author: {
|
||||||
return secp.utils.bytesToHex(data);
|
return secp.utils.bytesToHex(data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user