From 9b9c7ba370529228a2ebf825952ed475924f23be Mon Sep 17 00:00:00 2001 From: Bojan Mojsilovic Date: Mon, 15 Apr 2024 12:13:55 +0200 Subject: [PATCH] Parse naddr1 --- src/components/ParsedNote/ParsedNote.tsx | 42 +++++++++++++++++++++++- src/constants.ts | 2 ++ src/lib/notes.tsx | 3 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/components/ParsedNote/ParsedNote.tsx b/src/components/ParsedNote/ParsedNote.tsx index 75f067b..ae85bef 100644 --- a/src/components/ParsedNote/ParsedNote.tsx +++ b/src/components/ParsedNote/ParsedNote.tsx @@ -1,7 +1,9 @@ import { A } from '@solidjs/router'; import { hexToNpub } from '../../lib/keys'; import { + addLinkPreviews, getLinkPreview, + isAddrMention, isAppleMusic, isCustomEmoji, isHashtag, @@ -26,7 +28,7 @@ import { import { authorName, truncateNpub, userName } from '../../stores/profile'; import EmbeddedNote from '../EmbeddedNote/EmbeddedNote'; import { - Component, createSignal, For, JSXElement, onMount, Show, + Component, createResource, createSignal, For, JSXElement, onMount, Show, Suspense, } from 'solid-js'; import { PrimalNote, @@ -381,6 +383,12 @@ const ParsedNote: Component<{ return; } + if (isAddrMention(token)) { + lastSignificantContent = 'comunity'; + updateContent(content, 'comunity', token); + return; + } + if (isTagMention(token)) { lastSignificantContent = 'tagmention'; updateContent(content, 'tagmention', token); @@ -805,6 +813,37 @@ const ParsedNote: Component<{ }; + const renderComunityMention = (item: NoteContent, index?: number) => { + + return + {(token) => { + if (isNoteTooLong()) return; + + let [_, id] = token.split(':'); + + if (!id) { + return <>{token}; + } + + let end = ''; + + let match = specialCharsRegex.exec(id); + + if (match) { + const i = match.index; + end = id.slice(i); + id = id.slice(0, i); + } + + setWordsDisplayed(w => w + 1); + + const url = `https://highlighter.com/a/${id}`; + + return {token}; + }} + + } + const renderLongFormMention = (mention: PrimalNote | undefined, index?: number) => { if(!mention) return <>; @@ -1113,6 +1152,7 @@ const ParsedNote: Component<{ link: renderLinks, notemention: renderNoteMention, usermention: renderUserMention, + comunity: renderComunityMention, tagmention: renderTagMention, hashtag: renderHashtag, emoji: renderEmoji, diff --git a/src/constants.ts b/src/constants.ts index 42b1d4d..158bae6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -267,6 +267,8 @@ export const noteRegex = /nostr:((note|nevent)1\w+)\b/g; export const noteRegexLocal = /nostr:((note|nevent)1\w+)\b/; export const profileRegex = /nostr:((npub|nprofile)1\w+)\b/; export const profileRegexG = /nostr:((npub|nprofile)1\w+)\b/g; +export const addrRegex = /nostr:((naddr)1\w+)\b/; +export const addrRegexG = /nostr:((naddr)1\w+)\b/g; export const editMentionRegex = /(?:\s|^)@\`(.*?)\`/ig; export const specialCharsRegex = /[^A-Za-z0-9]/; diff --git a/src/lib/notes.tsx b/src/lib/notes.tsx index 18ee89e..8999384 100644 --- a/src/lib/notes.tsx +++ b/src/lib/notes.tsx @@ -3,7 +3,7 @@ import { A } from "@solidjs/router"; import { Relay, relayInit } from "nostr-tools"; import { createStore } from "solid-js/store"; import LinkPreview from "../components/LinkPreview/LinkPreview"; -import { appleMusicRegex, emojiRegex, hashtagRegex, interpunctionRegex, Kind, linebreakRegex, lnRegex, lnUnifiedRegex, mixCloudRegex, nostrNestsRegex, noteRegex, noteRegexLocal, profileRegex, profileRegexG, soundCloudRegex, spotifyRegex, tagMentionRegex, twitchRegex, urlRegex, urlRegexG, wavlakeRegex, youtubeRegex } from "../constants"; +import { addrRegex, appleMusicRegex, emojiRegex, hashtagRegex, interpunctionRegex, Kind, linebreakRegex, lnRegex, lnUnifiedRegex, mixCloudRegex, nostrNestsRegex, noteRegex, noteRegexLocal, profileRegex, profileRegexG, soundCloudRegex, spotifyRegex, tagMentionRegex, twitchRegex, urlRegex, urlRegexG, wavlakeRegex, youtubeRegex } from "../constants"; import { sendMessage, subscribeTo } from "../sockets"; import { MediaSize, NostrRelays, NostrRelaySignedEvent, PrimalNote, SendNoteResult } from "../types/primal"; import { logError, logInfo, logWarning } from "./logger"; @@ -58,6 +58,7 @@ export const isLinebreak = (url: string) => linebreakRegex.test(url); export const isTagMention = (url: string) => tagMentionRegex.test(url); export const isNoteMention = (url: string) => noteRegexLocal.test(url); export const isUserMention = (url: string) => profileRegex.test(url); +export const isAddrMention = (url: string) => addrRegex.test(url); export const isInterpunction = (url: string) => interpunctionRegex.test(url); export const isCustomEmoji = (url: string) => emojiRegex.test(url); export const isLnbc = (url: string) => lnRegex.test(url);