From c96ab921963e73c30987315ccc3ddf9f1bfbaff3 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Sat, 11 Oct 2025 13:37:03 +0200 Subject: [PATCH] fixed mentions bug --- package.json | 2 +- src/lib/nostr-address.ts | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 091e25c0..d9cf189b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jumble", - "version": "0.1.0", + "version": "10.1.0", "description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery", "private": true, "type": "module", diff --git a/src/lib/nostr-address.ts b/src/lib/nostr-address.ts index 6128aa9a..979c5359 100644 --- a/src/lib/nostr-address.ts +++ b/src/lib/nostr-address.ts @@ -14,19 +14,19 @@ const NOSTR_ADDRESS_REGEX = /\b(npub|nprofile|note|nevent|naddr|nrelay)1[a-z0-9] * @returns The content with nostr addresses properly prefixed */ export function prefixNostrAddresses(content: string): string { - return content.replace(NOSTR_ADDRESS_REGEX, (match) => { + return content.replace(NOSTR_ADDRESS_REGEX, (match, _p1, offset) => { // Check if it already has a prefix (nostr: or other protocol) - const beforeMatch = content.substring(0, content.indexOf(match)) - const lastSpace = beforeMatch.lastIndexOf(' ') - const lastNewline = beforeMatch.lastIndexOf('\n') - const lastDelimiter = Math.max(lastSpace, lastNewline) + // Look at the characters immediately before this specific match + const beforeMatch = content.substring(0, offset) - if (lastDelimiter >= 0) { - const prefix = content.substring(lastDelimiter + 1, content.indexOf(match)) - // If it already has nostr: prefix, don't add another - if (prefix.includes('nostr:')) { - return match - } + // Check if the match is already prefixed with "nostr:" + if (beforeMatch.endsWith('nostr:')) { + return match + } + + // Check if the match is prefixed with @ (for @mention style) + if (beforeMatch.endsWith('@')) { + return match } // Add nostr: prefix