Browse Source

fixed mentions bug

imwald
Silberengel 5 months ago
parent
commit
c96ab92196
  1. 2
      package.json
  2. 18
      src/lib/nostr-address.ts

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "jumble", "name": "jumble",
"version": "0.1.0", "version": "10.1.0",
"description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery", "description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery",
"private": true, "private": true,
"type": "module", "type": "module",

18
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 * @returns The content with nostr addresses properly prefixed
*/ */
export function prefixNostrAddresses(content: string): string { 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) // Check if it already has a prefix (nostr: or other protocol)
const beforeMatch = content.substring(0, content.indexOf(match)) // Look at the characters immediately before this specific match
const lastSpace = beforeMatch.lastIndexOf(' ') const beforeMatch = content.substring(0, offset)
const lastNewline = beforeMatch.lastIndexOf('\n')
const lastDelimiter = Math.max(lastSpace, lastNewline)
if (lastDelimiter >= 0) { // Check if the match is already prefixed with "nostr:"
const prefix = content.substring(lastDelimiter + 1, content.indexOf(match)) if (beforeMatch.endsWith('nostr:')) {
// If it already has nostr: prefix, don't add another
if (prefix.includes('nostr:')) {
return match return match
} }
// Check if the match is prefixed with @ (for @mention style)
if (beforeMatch.endsWith('@')) {
return match
} }
// Add nostr: prefix // Add nostr: prefix

Loading…
Cancel
Save