mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Handle profile and note mentions in profile bio
This commit is contained in:
parent
377569ce79
commit
4299b15abd
@ -1,8 +1,9 @@
|
|||||||
// @ts-ignore Bad types in nostr-tools
|
// @ts-ignore Bad types in nostr-tools
|
||||||
|
import { A } from "@solidjs/router";
|
||||||
import { Relay } from "nostr-tools";
|
import { Relay } 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, mixCloudRegex, nostrNestsRegex, noteRegex, noteRegexLocal, profileRegex, soundCloudRegex, spotifyRegex, tagMentionRegex, twitchRegex, urlRegex, urlRegexG, wavlakeRegex, youtubeRegex } from "../constants";
|
import { appleMusicRegex, emojiRegex, hashtagRegex, interpunctionRegex, Kind, linebreakRegex, 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";
|
||||||
@ -75,6 +76,33 @@ export const isNostrNests = (url: string) => nostrNestsRegex.test(url);
|
|||||||
export const isWavelake = (url: string) => wavlakeRegex.test(url);
|
export const isWavelake = (url: string) => wavlakeRegex.test(url);
|
||||||
|
|
||||||
|
|
||||||
|
export const linkifyNostrProfileLink = (text: string) => {
|
||||||
|
|
||||||
|
return text.replace(profileRegexG, (url) => {
|
||||||
|
if (isUserMention(url)) {
|
||||||
|
const npub = url.split('nostr:')[1];
|
||||||
|
// @ts-ignore
|
||||||
|
return (<span><A href={`/p/${npub}`}>{npub}</A></span>)?.innerHTML || url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export const linkifyNostrNoteLink = (text: string) => {
|
||||||
|
|
||||||
|
return text.replace(noteRegex, (url) => {
|
||||||
|
if (isNoteMention(url)) {
|
||||||
|
const noteId = url.split('nostr:')[1];
|
||||||
|
// @ts-ignore
|
||||||
|
return (<span><A href={`/e/${noteId}`}>{noteId}</A></span>)?.innerHTML || url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const urlify = (
|
export const urlify = (
|
||||||
text: string,
|
text: string,
|
||||||
getMediaUrl: ((url: string | undefined, size?: MediaSize, animated?: boolean) => string | undefined) | undefined,
|
getMediaUrl: ((url: string | undefined, size?: MediaSize, animated?: boolean) => string | undefined) | undefined,
|
||||||
|
@ -19,7 +19,7 @@ import { useProfileContext } from '../contexts/ProfileContext';
|
|||||||
import { useAccountContext } from '../contexts/AccountContext';
|
import { useAccountContext } from '../contexts/AccountContext';
|
||||||
import Wormhole from '../components/Wormhole/Wormhole';
|
import Wormhole from '../components/Wormhole/Wormhole';
|
||||||
import { useIntl } from '@cookbook/solid-intl';
|
import { useIntl } from '@cookbook/solid-intl';
|
||||||
import { urlify, sanitize } from '../lib/notes';
|
import { urlify, sanitize, linkifyNostrProfileLink, linkifyNostrNoteLink } from '../lib/notes';
|
||||||
import { shortDate } from '../lib/dates';
|
import { shortDate } from '../lib/dates';
|
||||||
|
|
||||||
import styles from './Profile.module.scss';
|
import styles from './Profile.module.scss';
|
||||||
@ -439,7 +439,7 @@ const Profile: Component = () => {
|
|||||||
const [renderProfileAbout, setRenderProfileAbout] = createSignal('');
|
const [renderProfileAbout, setRenderProfileAbout] = createSignal('');
|
||||||
|
|
||||||
const getProfileAbout = (about: string) => {
|
const getProfileAbout = (about: string) => {
|
||||||
const a = urlify(sanitize(about), () => '', false, false, true);
|
const a = linkifyNostrNoteLink(linkifyNostrProfileLink(urlify(sanitize(about), () => '', false, false, true)));
|
||||||
|
|
||||||
setRenderProfileAbout(a)
|
setRenderProfileAbout(a)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user