2023-01-02 11:15:13 +00:00
|
|
|
import "./NoteReaction.css";
|
2023-01-08 18:35:36 +00:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import { useMemo } from "react";
|
2023-03-28 14:34:01 +00:00
|
|
|
import { EventKind, RawEvent, TaggedRawEvent, NostrPrefix } from "@snort/nostr";
|
2023-01-20 11:11:50 +00:00
|
|
|
|
|
|
|
import Note from "Element/Note";
|
|
|
|
import ProfileImage from "Element/ProfileImage";
|
|
|
|
import { eventLink, hexToBech32 } from "Util";
|
|
|
|
import NoteTime from "Element/NoteTime";
|
2023-01-26 11:34:18 +00:00
|
|
|
import useModeration from "Hooks/useModeration";
|
2023-03-28 14:34:01 +00:00
|
|
|
import { EventExt } from "System/EventExt";
|
2023-01-02 11:15:13 +00:00
|
|
|
|
2023-01-16 17:48:25 +00:00
|
|
|
export interface NoteReactionProps {
|
2023-03-28 14:34:01 +00:00
|
|
|
data: TaggedRawEvent;
|
2023-02-07 20:04:50 +00:00
|
|
|
root?: TaggedRawEvent;
|
2023-01-16 17:48:25 +00:00
|
|
|
}
|
|
|
|
export default function NoteReaction(props: NoteReactionProps) {
|
2023-03-28 14:34:01 +00:00
|
|
|
const { data: ev } = props;
|
2023-02-07 20:04:50 +00:00
|
|
|
const { isMuted } = useModeration();
|
2023-01-02 11:15:13 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
const refEvent = useMemo(() => {
|
|
|
|
if (ev) {
|
2023-03-28 14:34:01 +00:00
|
|
|
const eTags = ev.tags.filter(a => a[0] === "e");
|
2023-02-07 20:04:50 +00:00
|
|
|
if (eTags.length > 0) {
|
2023-03-25 22:55:34 +00:00
|
|
|
return eTags[0];
|
2023-02-07 20:04:50 +00:00
|
|
|
}
|
2023-01-02 11:15:13 +00:00
|
|
|
}
|
2023-02-07 20:04:50 +00:00
|
|
|
return null;
|
|
|
|
}, [ev]);
|
2023-01-02 11:15:13 +00:00
|
|
|
|
2023-02-15 22:26:26 +00:00
|
|
|
if (
|
2023-03-28 14:34:01 +00:00
|
|
|
ev.kind !== EventKind.Reaction &&
|
|
|
|
ev.kind !== EventKind.Repost &&
|
|
|
|
(ev.kind !== EventKind.TextNote ||
|
|
|
|
ev.tags.every((a, i) => a[1] !== refEvent?.[1] || a[3] !== "mention" || ev.content !== `#[${i}]`))
|
2023-02-15 22:26:26 +00:00
|
|
|
) {
|
2023-02-07 20:04:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
2023-01-02 11:15:13 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
/**
|
|
|
|
* Some clients embed the reposted note in the content
|
|
|
|
*/
|
|
|
|
function extractRoot() {
|
2023-03-28 14:34:01 +00:00
|
|
|
if (ev?.kind === EventKind.Repost && ev.content.length > 0 && ev.content !== "#[0]") {
|
2023-02-07 20:04:50 +00:00
|
|
|
try {
|
2023-03-28 14:34:01 +00:00
|
|
|
const r: RawEvent = JSON.parse(ev.content);
|
2023-02-07 20:04:50 +00:00
|
|
|
return r as TaggedRawEvent;
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Could not load reposted content", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return props.root;
|
|
|
|
}
|
2023-01-17 00:54:08 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
const root = extractRoot();
|
|
|
|
const isOpMuted = root && isMuted(root.pubkey);
|
2023-03-08 17:30:19 +00:00
|
|
|
const shouldNotBeRendered = isOpMuted || root?.kind !== EventKind.TextNote;
|
2023-02-07 20:04:50 +00:00
|
|
|
const opt = {
|
2023-03-28 14:34:01 +00:00
|
|
|
showHeader: ev?.kind === EventKind.Repost || ev?.kind === EventKind.TextNote,
|
2023-02-07 20:04:50 +00:00
|
|
|
showFooter: false,
|
|
|
|
};
|
2023-01-02 11:15:13 +00:00
|
|
|
|
2023-03-08 17:30:19 +00:00
|
|
|
return shouldNotBeRendered ? null : (
|
2023-02-07 20:04:50 +00:00
|
|
|
<div className="reaction">
|
|
|
|
<div className="header flex">
|
2023-03-28 14:34:01 +00:00
|
|
|
<ProfileImage pubkey={EventExt.getRootPubKey(ev)} />
|
2023-02-07 20:04:50 +00:00
|
|
|
<div className="info">
|
2023-03-28 14:34:01 +00:00
|
|
|
<NoteTime from={ev.created_at * 1000} />
|
2023-01-02 11:15:13 +00:00
|
|
|
</div>
|
2023-02-07 20:04:50 +00:00
|
|
|
</div>
|
|
|
|
{root ? <Note data={root} options={opt} related={[]} /> : null}
|
|
|
|
{!root && refEvent ? (
|
|
|
|
<p>
|
2023-03-28 14:34:01 +00:00
|
|
|
<Link to={eventLink(refEvent[1] ?? "", refEvent[2])}>
|
|
|
|
#{hexToBech32(NostrPrefix.Event, refEvent[1]).substring(0, 12)}
|
2023-03-25 22:55:34 +00:00
|
|
|
</Link>
|
2023-02-07 20:04:50 +00:00
|
|
|
</p>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
2023-01-15 23:14:52 +00:00
|
|
|
}
|