diff --git a/.changeset/small-comics-try.md b/.changeset/small-comics-try.md new file mode 100644 index 000000000..04201e33b --- /dev/null +++ b/.changeset/small-comics-try.md @@ -0,0 +1,5 @@ +--- +"nostrudel": minor +--- + +Add NIP definitions when hovering over "NIP-xx" diff --git a/src/components/embed-types/nostr.tsx b/src/components/embed-types/nostr.tsx index 30a9372a5..f462ebf69 100644 --- a/src/components/embed-types/nostr.tsx +++ b/src/components/embed-types/nostr.tsx @@ -1,4 +1,4 @@ -import { Link } from "@chakra-ui/react"; +import { Link, Text, Tooltip } from "@chakra-ui/react"; import { Link as RouterLink } from "react-router-dom"; import { EmbedableContent, embedJSX } from "../../helpers/embeds"; @@ -7,6 +7,7 @@ import UserLink from "../user-link"; import { getMatchHashtag, getMatchNostrLink, stripInvisibleChar } from "../../helpers/regexp"; import { safeDecode } from "../../helpers/nip19"; import { EmbedEventPointer } from "../embed-event"; +import { NIP_NAMES } from "../../views/relays/components/supported-nips"; // nostr:nevent1qqsthg2qlxp9l7egtwa92t8lusm7pjknmjwa75ctrrpcjyulr9754fqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduq36amnwvaz7tmwdaehgu3dwp6kytnhv4kxcmmjv3jhytnwv46q2qg5q9 // nostr:nevent1qqsq3wc73lqxd70lg43m5rul57d4mhcanttjat56e30yx5zla48qzlspz9mhxue69uhkummnw3e82efwvdhk6qgdwaehxw309ahx7uewd3hkcq5hsum @@ -93,3 +94,22 @@ export function embedNostrHashtags(content: EmbedableContent, event: NostrEvent }, }); } + +export function embedNipDefinitions(content: EmbedableContent) { + return embedJSX(content, { + name: "nip-definition", + regexp: /nip-?(\d\d)/gi, + render: (match) => { + if (NIP_NAMES[match[1]]) { + return ( + + + {match[0]} + + + ); + } + return null; + }, + }); +} diff --git a/src/components/note/text-note-contents.tsx b/src/components/note/text-note-contents.tsx index bf6c45e8f..921e15fe9 100644 --- a/src/components/note/text-note-contents.tsx +++ b/src/components/note/text-note-contents.tsx @@ -26,6 +26,7 @@ import { renderSoundCloudUrl, renderSimpleXLink, renderRedditUrl, + embedNipDefinitions, } from "../embed-types"; import { LightboxProvider } from "../lightbox-provider"; @@ -63,6 +64,7 @@ function buildContents(event: NostrEvent | DraftNostrEvent, simpleLinks = false) content = embedNostrLinks(content); content = embedNostrMentions(content, event); content = embedNostrHashtags(content, event); + content = embedNipDefinitions(content); content = embedEmoji(content, event); return content; diff --git a/src/views/channels/components/channel-message-content.tsx b/src/views/channels/components/channel-message-content.tsx index 07636c5d1..128709305 100644 --- a/src/views/channels/components/channel-message-content.tsx +++ b/src/views/channels/components/channel-message-content.tsx @@ -9,6 +9,7 @@ import { embedEmoji, embedImageGallery, embedLightningInvoice, + embedNipDefinitions, embedNostrHashtags, embedNostrLinks, embedNostrMentions, @@ -64,6 +65,7 @@ const ChannelMessageContent = memo(({ message, children, ...props }: BoxProps & c = embedNostrLinks(c); c = embedNostrMentions(c, message); c = embedNostrHashtags(c, message); + c = embedNipDefinitions(c); c = embedEmoji(c, message); return c; diff --git a/src/views/relays/components/supported-nips.tsx b/src/views/relays/components/supported-nips.tsx index f49a11435..deb43444b 100644 --- a/src/views/relays/components/supported-nips.tsx +++ b/src/views/relays/components/supported-nips.tsx @@ -1,7 +1,7 @@ import { Flex, Tag, Tooltip } from "@chakra-ui/react"; // copied from github -const NIP_NAMES: Record = { +export const NIP_NAMES: Record = { "01": "Basic protocol", "02": "Contact List and Petnames", "03": "OpenTimestamps Attestations for Events", @@ -17,13 +17,13 @@ const NIP_NAMES: Record = { "13": "Proof of Work", "14": "Subject tag in text events", "15": "Nostr Marketplace", - "16": "Event Treatment", "18": "Reposts", "19": "bech32-encoded entities", "20": "Command Results", "21": "nostr: URI scheme", - "22": "Event created_at Limits", + "22": "Event created_at Limits", // removed "23": "Long-form Content", + "24": "Extra metadata fields and tags", "25": "Reactions", "26": "Delegated Event Signing", "27": "Text Note References", @@ -31,14 +31,17 @@ const NIP_NAMES: Record = { "30": "Custom Emoji", "31": "Dealing with Unknown Events", "32": "Labeling", - "33": "Parameterized Replaceable Events", + "33": "Parameterized Replaceable Events", //removed "36": "Sensitive Content", + "38": "User Statuses", "39": "External Identities in Profiles", "40": "Expiration Timestamp", "42": "Authentication of clients to relays", + "44": "Versioned Encryption", "45": "Counting results", "46": "Nostr Connect", "47": "Wallet Connect", + "48": "Proxy Tags", "50": "Keywords filter", "51": "Lists", "52": "Calendar Events", @@ -47,8 +50,12 @@ const NIP_NAMES: Record = { "57": "Lightning Zaps", "58": "Badges", "65": "Relay List Metadata", + "72": "Moderated Communities", + "75": "Zap Goals", "78": "Application-specific data", + "84": "Highlights", "89": "Recommended Application Handlers", + "90": "Data Vending Machines", "94": "File Metadata", "98": "HTTP Auth", "99": "Classified Listings", diff --git a/src/views/streams/components/stream-summary-content.tsx b/src/views/streams/components/stream-summary-content.tsx index e95988b8c..f9a51dc91 100644 --- a/src/views/streams/components/stream-summary-content.tsx +++ b/src/views/streams/components/stream-summary-content.tsx @@ -3,6 +3,7 @@ import { ParsedStream } from "../../../helpers/nostr/stream"; import { EmbedableContent, embedUrls } from "../../../helpers/embeds"; import { embedEmoji, + embedNipDefinitions, embedNostrHashtags, embedNostrLinks, embedNostrMentions, @@ -23,6 +24,7 @@ export default function StreamSummaryContent({ stream, ...props }: BoxProps & { c = embedNostrLinks(c); c = embedNostrMentions(c, stream.event); c = embedNostrHashtags(c, stream.event); + c = embedNipDefinitions(c); c = embedEmoji(c, stream.event); return c; diff --git a/src/views/streams/stream/stream-chat/chat-message-content.tsx b/src/views/streams/stream/stream-chat/chat-message-content.tsx index 2202dfafd..e09ee9d54 100644 --- a/src/views/streams/stream/stream-chat/chat-message-content.tsx +++ b/src/views/streams/stream/stream-chat/chat-message-content.tsx @@ -3,6 +3,7 @@ import React, { useMemo } from "react"; import { EmbedableContent, embedUrls } from "../../../../helpers/embeds"; import { embedEmoji, + embedNipDefinitions, embedNostrHashtags, embedNostrLinks, embedNostrMentions, @@ -24,6 +25,7 @@ const ChatMessageContent = React.memo(({ event }: { event: NostrEvent }) => { c = embedNostrLinks(c); c = embedNostrMentions(c, event); c = embedNostrHashtags(c, event); + c = embedNipDefinitions(c); c = embedEmoji(c, event); return c;