This commit is contained in:
Kieran 2023-08-30 10:03:04 +01:00
parent 3bbad28c32
commit 5521f685fc
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 25 additions and 5 deletions

View File

@ -27,9 +27,10 @@ import MagnetLink from "Element/MagnetLink";
interface HypeTextProps { interface HypeTextProps {
link: string; link: string;
depth?: number; depth?: number;
showLinkPreview?: boolean;
} }
export default function HyperText({ link, depth }: HypeTextProps) { export default function HyperText({ link, depth, showLinkPreview }: HypeTextProps) {
const a = link; const a = link;
try { try {
const url = new URL(a); const url = new URL(a);
@ -91,7 +92,7 @@ export default function HyperText({ link, depth }: HypeTextProps) {
if (parsed) { if (parsed) {
return <MagnetLink magnet={parsed} />; return <MagnetLink magnet={parsed} />;
} }
} else { } else if (showLinkPreview ?? true) {
return <LinkPreview url={a} />; return <LinkPreview url={a} />;
} }
} catch { } catch {

View File

@ -1,7 +1,7 @@
import "./NoteReaction.css"; import "./NoteReaction.css";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { useMemo } from "react"; import { useMemo } from "react";
import { EventKind, NostrEvent, TaggedNostrEvent, NostrPrefix } from "@snort/system"; import { EventKind, NostrEvent, TaggedNostrEvent, NostrPrefix, EventExt } from "@snort/system";
import Note from "Element/Note"; import Note from "Element/Note";
import { getDisplayName } from "Element/ProfileImage"; import { getDisplayName } from "Element/ProfileImage";
@ -46,6 +46,11 @@ export default function NoteReaction(props: NoteReactionProps) {
if (ev?.kind === EventKind.Repost && ev.content.length > 0 && ev.content !== "#[0]") { if (ev?.kind === EventKind.Repost && ev.content.length > 0 && ev.content !== "#[0]") {
try { try {
const r: NostrEvent = JSON.parse(ev.content); const r: NostrEvent = JSON.parse(ev.content);
EventExt.fixupEvent(r);
if(!EventExt.verify(r)) {
console.debug("Event in repost is invalid");
return undefined;
}
return r as TaggedNostrEvent; return r as TaggedNostrEvent;
} catch (e) { } catch (e) {
console.error("Could not load reposted content", e); console.error("Could not load reposted content", e);

View File

@ -63,7 +63,7 @@ export default function Text({ content, tags, creator, disableMedia, depth, disa
return <CashuNuts token={a.content} />; return <CashuNuts token={a.content} />;
case "media": case "media":
case "link": case "link":
return <HyperText link={a.content} depth={depth} />; return <HyperText link={a.content} depth={depth} showLinkPreview={!(disableMedia ?? false)}/>;
case "custom_emoji": case "custom_emoji":
return <ProxyImg src={a.content} size={15} className="custom-emoji" />; return <ProxyImg src={a.content} size={15} className="custom-emoji" />;
default: default:

View File

@ -121,8 +121,9 @@ export default function ProfilePage() {
const about = Text({ const about = Text({
content: aboutText, content: aboutText,
tags: [], tags: [],
creator: "", creator: id ?? "",
disableMedia: true, disableMedia: true,
disableMediaSpotlight: true,
}); });
const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id; const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id;

View File

@ -138,4 +138,17 @@ export abstract class EventExt {
ret.pubKeys = Array.from(new Set(ev.tags.filter(a => a[0] === "p").map(a => a[1]))); ret.pubKeys = Array.from(new Set(ev.tags.filter(a => a[0] === "p").map(a => a[1])));
return ret; return ret;
} }
/**
* Assign props if undefined
*/
static fixupEvent(e: NostrEvent) {
e.tags ??= [];
e.created_at ??= 0;
e.content ??= "";
e.id ??= "";
e.kind ??= 0;
e.pubkey ??= "";
e.sig ??= "";
}
} }