diff --git a/src/element/Note.js b/src/element/Note.js index 4ce18d3e3..86426fc4e 100644 --- a/src/element/Note.js +++ b/src/element/Note.js @@ -3,13 +3,19 @@ import Event from "../nostr/Event"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; import moment from "moment"; -import { useNavigate } from "react-router-dom"; +import { Link, useNavigate } from "react-router-dom"; +import { isFulfilled } from "@reduxjs/toolkit"; + +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 [sig, setSig] = useState(false); - const user = useSelector(s => s.users?.users[data?.pubkey]); + const users = useSelector(s => s.users?.users); + const user = users[data?.pubkey]; const ev = Event.FromObject(data); useEffect(() => { @@ -29,8 +35,10 @@ export default function Note(props) { } function goToEvent(e, id) { - e.stopPropagation(); - navigate(`/e/${id}`); + if (!window.location.pathname.startsWith("/e/")) { + e.stopPropagation(); + navigate(`/e/${id}`); + } } function replyTag() { @@ -40,13 +48,61 @@ export default function Note(props) { } 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)}> - ➡️ {replyId?.substring(0, 8)} + ➡️ {mentions?.join(", ") ?? replyId?.substring(0, 8)}
) } + function transformBody() { + let body = ev.Content; + let pTags = ev.Tags.filter(a => a.Key === "p"); + + 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