diff --git a/src/components/debug-modals/community-post-debug-modal.tsx b/src/components/debug-modals/community-post-debug-modal.tsx index 44cc35cd0..e504c4311 100644 --- a/src/components/debug-modals/community-post-debug-modal.tsx +++ b/src/components/debug-modals/community-post-debug-modal.tsx @@ -9,6 +9,7 @@ import RawPre from "./raw-pre"; import userMetadataService from "../../services/user-metadata"; import { getUserDisplayName } from "../../helpers/user-metadata"; import { COMMUNITY_DEFINITION_KIND } from "../../helpers/nostr/communities"; +import { getSharableEventAddress } from "../../helpers/nip19"; export default function CommunityPostDebugModal({ event, @@ -27,7 +28,8 @@ export default function CommunityPostDebugModal({ - + + diff --git a/src/components/debug-modals/note-debug-modal.tsx b/src/components/debug-modals/note-debug-modal.tsx index d64dfcf87..6a2baff1d 100644 --- a/src/components/debug-modals/note-debug-modal.tsx +++ b/src/components/debug-modals/note-debug-modal.tsx @@ -7,6 +7,7 @@ import { NostrEvent } from "../../types/nostr-event"; import RawJson from "./raw-json"; import RawValue from "./raw-value"; import RawPre from "./raw-pre"; +import { getSharableEventAddress } from "../../helpers/nip19"; export default function NoteDebugModal({ event, ...props }: { event: NostrEvent } & Omit) { return ( @@ -17,7 +18,8 @@ export default function NoteDebugModal({ event, ...props }: { event: NostrEvent - + + diff --git a/src/components/note-link.tsx b/src/components/note-link.tsx index 21b9db18c..78e65d3a5 100644 --- a/src/components/note-link.tsx +++ b/src/components/note-link.tsx @@ -1,20 +1,20 @@ import { useMemo } from "react"; import { Link, LinkProps } from "@chakra-ui/react"; import { Link as RouterLink } from "react-router-dom"; -import { nip19 } from "nostr-tools"; import { truncatedId } from "../helpers/nostr/events"; +import { getNeventCodeWithRelays } from "../helpers/nip19"; export type NoteLinkProps = LinkProps & { noteId: string; }; export const NoteLink = ({ children, noteId, color = "blue.500", ...props }: NoteLinkProps) => { - const encoded = useMemo(() => nip19.noteEncode(noteId), [noteId]); + const nevent = useMemo(() => getNeventCodeWithRelays(noteId), [noteId]); return ( - - {children || truncatedId(nip19.noteEncode(noteId))} + + {children || truncatedId(nevent)} ); }; diff --git a/src/components/note/index.tsx b/src/components/note/index.tsx index 4da1e1b58..165ef74ed 100644 --- a/src/components/note/index.tsx +++ b/src/components/note/index.tsx @@ -97,7 +97,7 @@ export const Note = React.memo( data-event-id={event.id} {...props} > - {clickable && } + {clickable && } @@ -108,7 +108,7 @@ export const Note = React.memo( {!hideDrawerButton && ( )} - + diff --git a/src/helpers/nip19.ts b/src/helpers/nip19.ts index 2166b413a..d2c6e52cc 100644 --- a/src/helpers/nip19.ts +++ b/src/helpers/nip19.ts @@ -83,6 +83,13 @@ export function getSharableEventAddress(event: NostrEvent) { } } +export function getNeventCodeWithRelays(eventId: string) { + const relays = getEventRelays(eventId).value; + const ranked = relayScoreboardService.getRankedRelays(relays); + const maxTwo = ranked.slice(0, 2); + return nip19.neventEncode({ id: eventId, relays: maxTwo }); +} + export function encodePointer(pointer: DecodeResult) { switch (pointer.type) { case "naddr": diff --git a/src/views/community/components/community-post-menu.tsx b/src/views/community/components/community-post-menu.tsx index 25be507b8..80c7de0b4 100644 --- a/src/views/community/components/community-post-menu.tsx +++ b/src/views/community/components/community-post-menu.tsx @@ -33,7 +33,6 @@ export default function CommunityPostMenu({ const { deleteEvent } = useDeleteEventContext(); - const noteId = nip19.noteEncode(event.id); const address = getSharableEventAddress(event); return ( @@ -56,11 +55,12 @@ export default function CommunityPostMenu({ window.navigator.clipboard.writeText("nostr:" + address)} icon={}> Copy Share Link - {noteId && ( - window.navigator.clipboard.writeText(noteId)} icon={}> - Copy Note ID - - )} + window.navigator.clipboard.writeText(nip19.noteEncode(event.id))} + icon={} + > + Copy Note ID + {account?.pubkey === event.pubkey && ( } color="red.500" onClick={() => deleteEvent(event)}> Delete Note diff --git a/src/views/note/index.tsx b/src/views/note/index.tsx index ec9f3e56e..884d67fe8 100644 --- a/src/views/note/index.tsx +++ b/src/views/note/index.tsx @@ -3,7 +3,7 @@ import { nip19 } from "nostr-tools"; import { useParams, Link as RouterLink } from "react-router-dom"; import Note from "../../components/note"; -import { isHexKey } from "../../helpers/nip19"; +import { getSharableEventAddress, isHexKey } from "../../helpers/nip19"; import { useThreadLoader } from "../../hooks/use-thread-loader"; import { ThreadPost } from "./components/thread-post"; import VerticalPageLayout from "../../components/vertical-page-layout"; @@ -59,7 +59,7 @@ export default function NoteView() { h="4rem" w="full" as={RouterLink} - to={`/n/${nip19.noteEncode(parentPosts[0].event.id)}`} + to={`/n/${getSharableEventAddress(parentPosts[0].event)}`} > View full thread ({parentPosts.length - 1})