From 13ab06e2540ec5484d754b6b47061da4b84bdaf1 Mon Sep 17 00:00:00 2001 From: silberengel Date: Sat, 23 Aug 2025 21:09:21 +0200 Subject: [PATCH] fixed parsing of notifications --- src/lib/components/Notifications.svelte | 9 ++++----- src/lib/utils/nostrUtils.ts | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/lib/components/Notifications.svelte b/src/lib/components/Notifications.svelte index b463ba6..d627de9 100644 --- a/src/lib/components/Notifications.svelte +++ b/src/lib/components/Notifications.svelte @@ -22,7 +22,6 @@ import { formatDate, neventEncode } from "$lib/utils"; import { NDKRelaySetFromNDK } from "$lib/utils/nostrUtils"; import { parseBasicmarkup } from "$lib/utils/markup/basicMarkupParser"; - import { processNostrIdentifiers } from "$lib/utils/nostrUtils"; import { repostContent } from "$lib/components/embedded_events/EmbeddedSnippets.svelte"; import { repostKinds } from "$lib/consts"; @@ -842,7 +841,7 @@
Comment:
- {#await processNostrIdentifiers(message.content, ndk) then parsed} + {#await parseBasicmarkup(message.content) then parsed} {@html parsed} {/await} @@ -850,7 +849,7 @@ {:else} - {#await processNostrIdentifiers(message.content || "No content", ndk) then parsed} + {#await parseBasicmarkup(message.content || "No content") then parsed} {@html parsed} {/await} {/if} @@ -952,7 +951,7 @@
Comment:
- {#await processNostrIdentifiers(notification.content, ndk) then parsed} + {#await parseBasicmarkup(notification.content) then parsed} {@html parsed} {/await} @@ -960,7 +959,7 @@ {:else} - {#await processNostrIdentifiers(notification.content || "No content", ndk) then parsed} + {#await parseBasicmarkup(notification.content || "No content") then parsed} {@html parsed} {/await} {/if} diff --git a/src/lib/utils/nostrUtils.ts b/src/lib/utils/nostrUtils.ts index 31138c7..32072e0 100644 --- a/src/lib/utils/nostrUtils.ts +++ b/src/lib/utils/nostrUtils.ts @@ -191,6 +191,7 @@ export function createNoteLink(identifier: string): string { /** * Process Nostr identifiers in text */ +// AI-NOTE: 2025-01-24 - Enhanced URL detection to prevent processing nostr identifiers that are part of URLs export async function processNostrIdentifiers( content: string, ndk: NDK, @@ -201,7 +202,25 @@ export async function processNostrIdentifiers( function isPartOfUrl(text: string, index: number): boolean { // Look for http(s):// or www. before the match const before = text.slice(Math.max(0, index - 12), index); - return /https?:\/\/$|www\.$/i.test(before); + if (/https?:\/\/$|www\.$/i.test(before)) { + return true; + } + + // Check if the match is part of a larger URL structure + // Look for common URL patterns that might contain nostr identifiers + const beforeContext = text.slice(Math.max(0, index - 50), index); + const afterContext = text.slice(index, Math.min(text.length, index + 50)); + + // Check if there's a URL-like structure around the match + const urlPatterns = [ + /https?:\/\/[^\s]*$/i, // URL starting with http(s):// + /www\.[^\s]*$/i, // URL starting with www. + /[^\s]*\.(com|org|net|io|eu|co|me|app|dev)[^\s]*$/i, // Common TLDs + /[^\s]*\/[^\s]*$/i, // Path-like structures + ]; + + const combinedContext = beforeContext + afterContext; + return urlPatterns.some(pattern => pattern.test(combinedContext)); } // Process profiles (npub and nprofile)