import "./Note.css"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; import moment from "moment"; import { Link, useNavigate } from "react-router-dom"; import Event from "../nostr/Event"; import ProfileImage from "./ProfileImage"; import useEventPublisher from "../pages/feed/EventPublisher"; const UrlRegex = /((?:http|ftp|https):\/\/(?:[\w+?\.\w+])+(?:[a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?)/; const FileExtensionRegex = /\.([\w]+)$/; const MentionRegex = /(#\[\d+\])/g; export default function Note(props) { const navigate = useNavigate(); const data = props.data; const dataEvent = props["data-ev"]; const reactions = props.reactions; const publisher = useEventPublisher(); const [sig, setSig] = useState(false); const users = useSelector(s => s.users?.users); const ev = dataEvent ?? Event.FromObject(data); useEffect(() => { if (sig === false) { verifyEvent(); } }, []); async function verifyEvent() { let res = await ev.Verify(); setSig(res); } function goToEvent(e, id) { if (!window.location.pathname.startsWith("/e/")) { e.stopPropagation(); navigate(`/e/${id}`); } } function replyTag() { let thread = ev.GetThread(); if (thread === null) { return null; } let replyId = thread?.ReplyTo?.Event; let mentions = thread?.PubKeys?.map(a => [a, users[a]])?.map(a => a[1]?.name ?? a[0].substring(0, 8)); return (
goToEvent(e, replyId)}> ➡️ {mentions?.join(", ") ?? replyId?.substring(0, 8)}
) } function transformBody() { let body = ev.Content; let urlBody = body.split(UrlRegex); return urlBody.map(a => { if (a.startsWith("http")) { let url = new URL(a); let ext = url.pathname.match(FileExtensionRegex); if (ext) { switch (ext[1]) { case "gif": case "jpg": case "jpeg": case "png": case "bmp": case "webp": { return ; } case "mp4": case "mkv": case "avi": case "m4v": { return