mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Parse naddr1
This commit is contained in:
parent
8dd1f36f83
commit
9b9c7ba370
@ -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<{
|
||||
</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) => {
|
||||
if(!mention) return <></>;
|
||||
|
||||
@ -1113,6 +1152,7 @@ const ParsedNote: Component<{
|
||||
link: renderLinks,
|
||||
notemention: renderNoteMention,
|
||||
usermention: renderUserMention,
|
||||
comunity: renderComunityMention,
|
||||
tagmention: renderTagMention,
|
||||
hashtag: renderHashtag,
|
||||
emoji: renderEmoji,
|
||||
|
@ -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]/;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user