Fix rendering mentions inside of URLs

This commit is contained in:
Alex Gleason
2024-09-07 09:41:29 -05:00
parent 1a98049ee8
commit ddba16551a
2 changed files with 33 additions and 13 deletions

View File

@@ -123,21 +123,25 @@ const createStatusController: AppController = async (c) => {
const pubkeys = new Set<string>();
const content = await asyncReplaceAll(data.status ?? '', /@([\w@+._]+)/g, async (match, username) => {
const pubkey = await lookupPubkey(username);
if (!pubkey) return match;
const content = await asyncReplaceAll(
data.status ?? '',
/(?<![\w/])@([\w@+._]+)(?![\w/\.])/g,
async (match, username) => {
const pubkey = await lookupPubkey(username);
if (!pubkey) return match;
// Content addressing (default)
if (!data.to) {
pubkeys.add(pubkey);
}
// Content addressing (default)
if (!data.to) {
pubkeys.add(pubkey);
}
try {
return `nostr:${nip19.npubEncode(pubkey)}`;
} catch {
return match;
}
});
try {
return `nostr:${nip19.npubEncode(pubkey)}`;
} catch {
return match;
}
},
);
// Explicit addressing
for (const to of data.to ?? []) {