fix(concord): render imeta-only images in the chat feed too

The earlier imeta-only fix patched RenderChat (the thread-view path), but
the Concord channel feed renders messages through ChatMessageCompose →
RenderRegularTextNote, which handed the raw decrypted content straight to
the media renderer. So a NIP-C7/Concord image message from an interop
client (e.g. Ditto/Soapbox Armada) — empty content, image carried only as
a NIP-92 `imeta` tag — never rendered in the feed, even though the
encrypted blob's key/nonce were already registered for transparent
decryption at ingest.

Extract appendMissingImetaUrls into a shared helper (ui/note/types/
ImetaContent.kt) and apply it in RenderRegularTextNote against the
decrypted content, symmetric to the RenderChat fix and to
ChannelChat.imageMessage which appends the URL on send. Normal messages
whose imeta URLs are already inline are untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SF85F6GHu7aQZYpTGNYdWk
This commit is contained in:
Claude
2026-07-15 19:26:13 +00:00
parent 21b98b3ebf
commit 3892ade0a3
3 changed files with 57 additions and 17 deletions
@@ -41,10 +41,8 @@ import com.vitorpamplona.amethyst.ui.note.elements.DisplayUncitedHashtags
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hasHashtags
import com.vitorpamplona.quartz.nip10Notes.BaseNoteEvent
import com.vitorpamplona.quartz.nip92IMeta.imetas
@Composable
fun RenderChat(
@@ -66,7 +64,7 @@ fun RenderChat(
// from the content so those attachments render — symmetric to ChannelChat.imageMessage, which
// appends the URL on send. Encrypted-blob key/nonce are already registered by URL, so the shared
// pipeline fetches and decrypts them transparently.
val displayContent = remember(noteEvent) { appendMissingImetaUrls(noteEvent) }
val displayContent = remember(noteEvent) { appendMissingImetaUrls(noteEvent.content, noteEvent) }
// A boosted note inside a zap/nutzap/onchain activity card is always shown as a
// compact 2-line preview, even when the logged-in user is only a zap-split
@@ -129,16 +127,3 @@ fun RenderChat(
}
}
}
/**
* Returns [event]'s content with every NIP-92 `imeta` URL that is not already present appended on its
* own line, so an attachment carried only as an `imeta` tag (empty/incomplete content) still renders.
* Returns the original content unchanged when every imeta URL is already inline (the common case), so
* normal messages are untouched.
*/
private fun appendMissingImetaUrls(event: Event): String {
val content = event.content
val missing = event.imetas().map { it.url }.filter { it.isNotBlank() && !content.contains(it) }
if (missing.isEmpty()) return content
return (listOf(content) + missing).filter { it.isNotBlank() }.joinToString("\n")
}
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.ui.note.types
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip92IMeta.imetas
/**
* Returns [content] with every NIP-92 `imeta` URL on [event] that is not already present appended on
* its own line, so an attachment carried only as an `imeta` tag (empty/incomplete content) still
* renders. The shared media renderer only shows media whose URL appears in the text, but some
* NIP-C7/Concord clients (e.g. Ditto/Soapbox Armada) attach an image purely as an `imeta` tag and
* leave the content empty — symmetric to
* [com.vitorpamplona.quartz.concord.cord03Channels.ChannelChat.imageMessage], which appends the URL
* on send. Encrypted-blob key/nonce are already registered by URL, so the shared pipeline fetches and
* decrypts them transparently.
*
* Returns [content] unchanged when [event] is null or every imeta URL is already inline (the common
* case), so normal messages are untouched.
*/
fun appendMissingImetaUrls(
content: String,
event: Event?,
): String {
if (event == null) return content
val missing = event.imetas().map { it.url }.filter { it.isNotBlank() && !content.contains(it) }
if (missing.isEmpty()) return content
return (listOf(content) + missing).filter { it.isNotBlank() }.joinToString("\n")
}
@@ -33,6 +33,7 @@ import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
import com.vitorpamplona.amethyst.ui.note.LoadDecryptedContentOrNull
import com.vitorpamplona.amethyst.ui.note.types.appendMissingImetaUrls
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.stringRes
@@ -53,8 +54,15 @@ fun RenderRegularTextNote(
) {
val tags = remember(note.event) { note.event?.tags?.toImmutableListOfLists() ?: EmptyTagList }
// Some NIP-C7/Concord clients (e.g. Ditto/Soapbox Armada) attach an image purely as a
// NIP-92 `imeta` tag and leave the content empty. The shared renderer only shows media
// whose URL appears in the text, so append any imeta URL missing from the (decrypted)
// content — encrypted-blob key/nonce are already registered by URL, so the shared
// pipeline fetches and decrypts them transparently.
val displayContent = remember(note.event, eventContent) { appendMissingImetaUrls(eventContent, note.event) }
TranslatableRichTextViewer(
content = eventContent,
content = displayContent,
canPreview = canPreview,
quotesLeft = if (innerQuote) 0 else 1,
modifier = Modifier,