Revert "Merge branch 'nip19-mentions' into 'main'"

This reverts merge request !353
This commit is contained in:
Alex Gleason 2024-06-03 17:49:24 +00:00
parent 844103c047
commit a4b96f0a9c
1 changed files with 20 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import 'linkify-plugin-hashtag';
import linkifyStr from 'linkify-string';
import linkify from 'linkifyjs';
import { nip21 } from 'nostr-tools';
import { nip19, nip21 } from 'nostr-tools';
import { Conf } from '@/config.ts';
import { getUrlMediaType, isPermittedMediaType } from '@/utils/media.ts';
@ -18,10 +18,15 @@ const linkifyOpts: linkify.Opts = {
},
url: ({ content }) => {
try {
const { value } = nip21.parse(content);
const name = value.substring(0, 8);
const href = Conf.local(`/@${value}`);
return `<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>`;
const { decoded } = nip21.parse(content);
const pubkey = getDecodedPubkey(decoded);
if (pubkey) {
const name = pubkey.substring(0, 8);
const href = Conf.local(`/users/${pubkey}`);
return `<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>`;
} else {
return '';
}
} catch {
return `<a href="${content}">${content}</a>`;
}
@ -103,4 +108,14 @@ function isLinkURL(link: Link): boolean {
return link.type === 'url';
}
/** Get pubkey from decoded bech32 entity, or undefined if not applicable. */
function getDecodedPubkey(decoded: nip19.DecodeResult): string | undefined {
switch (decoded.type) {
case 'npub':
return decoded.data;
case 'nprofile':
return decoded.data.pubkey;
}
}
export { getMediaLinks, parseNoteContent, stripimeta };