Parse naddr1

This commit is contained in:
Bojan Mojsilovic 2024-04-15 12:13:55 +02:00
parent 8dd1f36f83
commit 9b9c7ba370
3 changed files with 45 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import { A } from '@solidjs/router'; import { A } from '@solidjs/router';
import { hexToNpub } from '../../lib/keys'; import { hexToNpub } from '../../lib/keys';
import { import {
addLinkPreviews,
getLinkPreview, getLinkPreview,
isAddrMention,
isAppleMusic, isAppleMusic,
isCustomEmoji, isCustomEmoji,
isHashtag, isHashtag,
@ -26,7 +28,7 @@ import {
import { authorName, truncateNpub, userName } from '../../stores/profile'; import { authorName, truncateNpub, userName } from '../../stores/profile';
import EmbeddedNote from '../EmbeddedNote/EmbeddedNote'; import EmbeddedNote from '../EmbeddedNote/EmbeddedNote';
import { import {
Component, createSignal, For, JSXElement, onMount, Show, Component, createResource, createSignal, For, JSXElement, onMount, Show, Suspense,
} from 'solid-js'; } from 'solid-js';
import { import {
PrimalNote, PrimalNote,
@ -381,6 +383,12 @@ const ParsedNote: Component<{
return; return;
} }
if (isAddrMention(token)) {
lastSignificantContent = 'comunity';
updateContent(content, 'comunity', token);
return;
}
if (isTagMention(token)) { if (isTagMention(token)) {
lastSignificantContent = 'tagmention'; lastSignificantContent = 'tagmention';
updateContent(content, 'tagmention', token); updateContent(content, 'tagmention', token);
@ -805,6 +813,37 @@ const ParsedNote: Component<{
</For> </For>
}; };
const renderComunityMention = (item: NoteContent, index?: number) => {
return <For each={item.tokens}>
{(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 <a href={url} target="_blank" >{token}</a>;
}}
</For>
}
const renderLongFormMention = (mention: PrimalNote | undefined, index?: number) => { const renderLongFormMention = (mention: PrimalNote | undefined, index?: number) => {
if(!mention) return <></>; if(!mention) return <></>;
@ -1113,6 +1152,7 @@ const ParsedNote: Component<{
link: renderLinks, link: renderLinks,
notemention: renderNoteMention, notemention: renderNoteMention,
usermention: renderUserMention, usermention: renderUserMention,
comunity: renderComunityMention,
tagmention: renderTagMention, tagmention: renderTagMention,
hashtag: renderHashtag, hashtag: renderHashtag,
emoji: renderEmoji, emoji: renderEmoji,

View File

@ -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 noteRegexLocal = /nostr:((note|nevent)1\w+)\b/;
export const profileRegex = /nostr:((npub|nprofile)1\w+)\b/; export const profileRegex = /nostr:((npub|nprofile)1\w+)\b/;
export const profileRegexG = /nostr:((npub|nprofile)1\w+)\b/g; 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 editMentionRegex = /(?:\s|^)@\`(.*?)\`/ig;
export const specialCharsRegex = /[^A-Za-z0-9]/; export const specialCharsRegex = /[^A-Za-z0-9]/;

View File

@ -3,7 +3,7 @@ import { A } from "@solidjs/router";
import { Relay, relayInit } from "nostr-tools"; import { Relay, relayInit } from "nostr-tools";
import { createStore } from "solid-js/store"; import { createStore } from "solid-js/store";
import LinkPreview from "../components/LinkPreview/LinkPreview"; 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 { sendMessage, subscribeTo } from "../sockets";
import { MediaSize, NostrRelays, NostrRelaySignedEvent, PrimalNote, SendNoteResult } from "../types/primal"; import { MediaSize, NostrRelays, NostrRelaySignedEvent, PrimalNote, SendNoteResult } from "../types/primal";
import { logError, logInfo, logWarning } from "./logger"; 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 isTagMention = (url: string) => tagMentionRegex.test(url);
export const isNoteMention = (url: string) => noteRegexLocal.test(url); export const isNoteMention = (url: string) => noteRegexLocal.test(url);
export const isUserMention = (url: string) => profileRegex.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 isInterpunction = (url: string) => interpunctionRegex.test(url);
export const isCustomEmoji = (url: string) => emojiRegex.test(url); export const isCustomEmoji = (url: string) => emojiRegex.test(url);
export const isLnbc = (url: string) => lnRegex.test(url); export const isLnbc = (url: string) => lnRegex.test(url);