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";
parsedContent = event.content; parsedContent = event.content;
} else { } else {
// For all other events (including quote reposts), parse the content using basic markup parser // 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; parsedContent = processed;
}).catch((error) => { }).catch((error) => {
console.error("Error parsing content:", error); console.error("Error parsing content:", error);

10
src/lib/components/Notifications.svelte

@ -841,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 parseBasicmarkup(message.content) then parsed} {#await parseBasicmarkup(message.content, ndk) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
</div> </div>
@ -849,7 +849,7 @@
</div> </div>
{:else} {:else}
<!-- Regular content --> <!-- Regular content -->
{#await parseBasicmarkup(message.content || "No content") then parsed} {#await parseBasicmarkup(message.content || "No content", ndk) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
{/if} {/if}
@ -951,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 parseBasicmarkup(notification.content) then parsed} {#await parseBasicmarkup(notification.content, ndk) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
</div> </div>
@ -959,7 +959,7 @@
</div> </div>
{:else} {:else}
<!-- Regular content --> <!-- Regular content -->
{#await parseBasicmarkup(notification.content || "No content") then parsed} {#await parseBasicmarkup(notification.content || "No content", ndk) then parsed}
{@html parsed} {@html parsed}
{/await} {/await}
{/if} {/if}
@ -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-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-800 dark:text-gray-200">
<div class="text-sm text-gray-700 dark:text-gray-300"> <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} {@html parsed}
{/await} {/await}
</div> </div>

9
src/lib/snippets/UserSnippets.svelte

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

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

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

Loading…
Cancel
Save