Browse Source

fixed npub display in notifications and eventdetails

master
silberengel 7 months ago
parent
commit
9fff4fb626
  1. 2
      src/lib/components/EventDetails.svelte
  2. 10
      src/lib/components/Notifications.svelte
  3. 9
      src/lib/snippets/UserSnippets.svelte
  4. 5
      src/lib/utils/markup/basicMarkupParser.ts

2
src/lib/components/EventDetails.svelte

@ -288,7 +288,7 @@ import type { UserProfile } from "$lib/models/user_profile"; @@ -288,7 +288,7 @@ import type { UserProfile } from "$lib/models/user_profile";
parsedContent = event.content;
} else {
// For all other events (including quote reposts), parse the content using basic markup parser
parseBasicmarkup(event.content).then((processed) => {
parseBasicmarkup(event.content, getNdkContext()).then((processed) => {
parsedContent = processed;
}).catch((error) => {
console.error("Error parsing content:", error);

10
src/lib/components/Notifications.svelte

@ -841,7 +841,7 @@ @@ -841,7 +841,7 @@
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">
Comment:
</div>
{#await parseBasicmarkup(message.content) then parsed}
{#await parseBasicmarkup(message.content, ndk) then parsed}
{@html parsed}
{/await}
</div>
@ -849,7 +849,7 @@ @@ -849,7 +849,7 @@
</div>
{:else}
<!-- Regular content -->
{#await parseBasicmarkup(message.content || "No content") then parsed}
{#await parseBasicmarkup(message.content || "No content", ndk) then parsed}
{@html parsed}
{/await}
{/if}
@ -951,7 +951,7 @@ @@ -951,7 +951,7 @@
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">
Comment:
</div>
{#await parseBasicmarkup(notification.content) then parsed}
{#await parseBasicmarkup(notification.content, ndk) then parsed}
{@html parsed}
{/await}
</div>
@ -959,7 +959,7 @@ @@ -959,7 +959,7 @@
</div>
{:else}
<!-- Regular content -->
{#await parseBasicmarkup(notification.content || "No content") then parsed}
{#await parseBasicmarkup(notification.content || "No content", ndk) then parsed}
{@html parsed}
{/await}
{/if}
@ -999,7 +999,7 @@ @@ -999,7 +999,7 @@
<div class="text-sm text-gray-600 dark:text-gray-400 mb-1">Replying to:</div>
<div class="text-sm text-gray-800 dark:text-gray-200">
<div class="text-sm text-gray-700 dark:text-gray-300">
{#await parseBasicmarkup(replyToMessage.content || "No content") then parsed}
{#await parseBasicmarkup(replyToMessage.content || "No content", ndk) then parsed}
{@html parsed}
{/await}
</div>

9
src/lib/snippets/UserSnippets.svelte

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
getUserMetadata,
} from "$lib/utils/nostrUtils";
import type { UserProfile } from "$lib/models/user_profile";
import { getNdkContext } from "$lib/ndk";
export { userBadge };
</script>
@ -14,8 +15,9 @@ @@ -14,8 +15,9 @@
{@const npub = toNpub(identifier)}
{#if npub}
{#if !displayText || displayText.trim().toLowerCase() === "unknown"}
{#await getUserMetadata(npub, undefined, false) then profile}
{#await getUserMetadata(npub, getNdkContext(), false) then profile}
{@const p = profile as UserProfile}
{@const debugInfo = console.log("Profile data for", npub, ":", p)}
<span class="inline-flex items-center gap-0.5">
<button
class="npub-badge bg-transparent border-none p-0 underline cursor-pointer"
@ -27,7 +29,8 @@ @@ -27,7 +29,8 @@
npub.slice(0, 8) + "..." + npub.slice(-4)}
</button>
</span>
{:catch}
{:catch error}
{@const debugError = console.error("Error fetching profile for", npub, ":", error)}
<span class="inline-flex items-center gap-0.5">
<button
class="npub-badge bg-transparent border-none p-0 underline cursor-pointer"
@ -38,7 +41,7 @@ @@ -38,7 +41,7 @@
</span>
{/await}
{:else}
{#await createProfileLinkWithVerification(npub as string, displayText, undefined)}
{#await createProfileLinkWithVerification(npub as string, displayText, getNdkContext())}
<span class="inline-flex items-center gap-0.5">
<button
class="npub-badge bg-transparent border-none p-0 underline cursor-pointer"

5
src/lib/utils/markup/basicMarkupParser.ts

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
import { nip19 } from "nostr-tools";
import NDK from "@nostr-dev-kit/ndk";
import {
processBasicTextFormatting,
processBlockquotes,
@ -216,7 +217,7 @@ function processBasicFormatting(content: string): string { @@ -216,7 +217,7 @@ function processBasicFormatting(content: string): string {
return processedText;
}
export async function parseBasicmarkup(text: string): Promise<string> {
export async function parseBasicmarkup(text: string, ndk?: NDK): Promise<string> {
if (!text) return "";
try {
@ -251,7 +252,7 @@ export async function parseBasicmarkup(text: string): Promise<string> { @@ -251,7 +252,7 @@ export async function parseBasicmarkup(text: string): Promise<string> {
.join("\n");
// Process Nostr identifiers last
processedText = await processNostrIdentifiersInText(processedText);
processedText = await processNostrIdentifiersInText(processedText, ndk);
// Replace wikilinks
processedText = processWikilinks(processedText);

Loading…
Cancel
Save