Browse Source

fixed parsing of notifications

master
silberengel 7 months ago
parent
commit
13ab06e254
  1. 9
      src/lib/components/Notifications.svelte
  2. 21
      src/lib/utils/nostrUtils.ts

9
src/lib/components/Notifications.svelte

@ -22,7 +22,6 @@
import { formatDate, neventEncode } from "$lib/utils"; import { formatDate, neventEncode } from "$lib/utils";
import { NDKRelaySetFromNDK } from "$lib/utils/nostrUtils"; import { NDKRelaySetFromNDK } from "$lib/utils/nostrUtils";
import { parseBasicmarkup } from "$lib/utils/markup/basicMarkupParser"; import { parseBasicmarkup } from "$lib/utils/markup/basicMarkupParser";
import { processNostrIdentifiers } from "$lib/utils/nostrUtils";
import { repostContent } from "$lib/components/embedded_events/EmbeddedSnippets.svelte"; import { repostContent } from "$lib/components/embedded_events/EmbeddedSnippets.svelte";
import { repostKinds } from "$lib/consts"; import { repostKinds } from "$lib/consts";
@ -842,7 +841,7 @@
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1"> <div class="text-xs text-gray-500 dark:text-gray-400 mb-1">
Comment: Comment:
</div> </div>
{#await processNostrIdentifiers(message.content, ndk) then parsed} {#await parseBasicmarkup(message.content) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
</div> </div>
@ -850,7 +849,7 @@
</div> </div>
{:else} {:else}
<!-- Regular content --> <!-- Regular content -->
{#await processNostrIdentifiers(message.content || "No content", ndk) then parsed} {#await parseBasicmarkup(message.content || "No content") then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
{/if} {/if}
@ -952,7 +951,7 @@
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1"> <div class="text-xs text-gray-500 dark:text-gray-400 mb-1">
Comment: Comment:
</div> </div>
{#await processNostrIdentifiers(notification.content, ndk) then parsed} {#await parseBasicmarkup(notification.content) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
</div> </div>
@ -960,7 +959,7 @@
</div> </div>
{:else} {:else}
<!-- Regular content --> <!-- Regular content -->
{#await processNostrIdentifiers(notification.content || "No content", ndk) then parsed} {#await parseBasicmarkup(notification.content || "No content") then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
{/if} {/if}

21
src/lib/utils/nostrUtils.ts

@ -191,6 +191,7 @@ export function createNoteLink(identifier: string): string {
/** /**
* Process Nostr identifiers in text * 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( export async function processNostrIdentifiers(
content: string, content: string,
ndk: NDK, ndk: NDK,
@ -201,7 +202,25 @@ export async function processNostrIdentifiers(
function isPartOfUrl(text: string, index: number): boolean { function isPartOfUrl(text: string, index: number): boolean {
// Look for http(s):// or www. before the match // Look for http(s):// or www. before the match
const before = text.slice(Math.max(0, index - 12), index); 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) // Process profiles (npub and nprofile)

Loading…
Cancel
Save