aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-06 23:56:57 -0800
committerAdam Soltys <[email protected]>2026-03-06 23:56:57 -0800
commita1400eea7b1bd9b7e66c0a698bfb02dc82eadb48 (patch)
tree2c13d94bc933da6a83b01d3039dfe8d76cd66673 /src/components
parent6468701ead38fa8edec1366af23f694f6149d46e (diff)
downloadcoinos-ui-a1400eea7b1bd9b7e66c0a698bfb02dc82eadb48.tar.gz
coinos-ui-a1400eea7b1bd9b7e66c0a698bfb02dc82eadb48.zip
simplify imeta image rendering to plain string array
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ChatMessage.svelte32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/components/ChatMessage.svelte b/src/components/ChatMessage.svelte
index 8f8db31a..aeaac210 100644
--- a/src/components/ChatMessage.svelte
+++ b/src/components/ChatMessage.svelte
@@ -3,21 +3,14 @@
let { content, tags = [] }: { content: string; tags?: any[] } = $props();
- // Extract media from imeta tags (NIP-92)
- let imetaMedia = $derived(
+ // Extract image URLs from imeta tags (NIP-92)
+ let imageUrls: string[] = $derived(
tags
- .filter((t) => t[0] === "imeta")
- .map((t) => ({
- url: t.find((v) => v.startsWith("url "))?.slice(4) || "",
- mime: t.find((v) => v.startsWith("m "))?.slice(2) || "",
- }))
- .filter((m) => m.url),
+ .filter((t: string[]) => t[0] === "imeta" && t.some((v) => v.startsWith("m image/")))
+ .map((t: string[]) => t.find((v) => v.startsWith("url "))?.slice(4))
+ .filter((url): url is string => !!url),
);
- $effect(() => {
- console.log("[ChatMessage]", { content, tags: JSON.stringify(tags), imetaMedia: JSON.stringify(imetaMedia) });
- });
-
let parts = $derived(parseContent({ content, tags }));
const truncUrl = (url: string) => {
@@ -37,17 +30,10 @@
};
</script>
-{#each imetaMedia as media}
- {#if media.mime.startsWith("image/")}
- <a href={media.url} target="_blank" rel="noopener noreferrer">
- <img src={media.url} alt="" class="chat-img" />
- </a>
- {:else if media.mime.startsWith("video/")}
- <!-- svelte-ignore a11y_media_has_caption -->
- <video src={media.url} controls class="chat-video"></video>
- {:else}
- <a href={media.url} target="_blank" rel="noopener noreferrer" class="chat-link">{truncUrl(media.url)}</a>
- {/if}
+{#each imageUrls as url}
+ <a href={url} target="_blank" rel="noopener noreferrer">
+ <img src={url} alt="" class="chat-img" />
+ </a>
{/each}
{#each parts as { type, value }}