From ab85352bfbe56cab3412e76d96320818e3ebe529 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Fri, 1 May 2026 19:44:32 +0200 Subject: [PATCH] Add toString for contentSegment --- .../intermdiate/LocalQuotedNostrEvent.kt | 14 ++-- .../widgets/content/ContentSegment.kt | 82 ++++++++++++++++--- .../composable/widgets/content/RichContent.kt | 3 +- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt index f1b19254..7d5ad2ad 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt @@ -5,6 +5,7 @@ import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.QuotedRelation import ac.cord.auxiliary.compose.extensions.toFormattedTimeAndDateString +import ac.cord.auxiliary.compose.ui.composable.widgets.content.RichContent import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileAvatar import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -76,15 +77,10 @@ data class LocalQuotedNostrEvent( } } - // TODO: Use RichContent... - Text( - modifier = Modifier.fillMaxWidth().padding( - horizontal = 20.dp - ), - style = MaterialTheme.typography.labelSmall, - textAlign = TextAlign.Start, - overflow = TextOverflow.Ellipsis, - text = nostrEvent.content + RichContent( + nostrEvent = nostrEvent, + localQuotedNostrEvent = null, + mentionedProfiles = mentionedProfiles, ) Row( modifier = Modifier.fillMaxWidth().padding(20.dp), diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentSegment.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentSegment.kt index dcc261a8..cbfb4352 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentSegment.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentSegment.kt @@ -1,18 +1,80 @@ package ac.cord.auxiliary.compose.ui.composable.widgets.content +import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl +import com.vitorpamplona.quartz.nip19Bech32.entities.NAddress +import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent +import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile import fr.acinq.lightning.payment.Bolt11Invoice internal sealed interface ContentSegment { - data class TextSegment(val text: String) : ContentSegment - data class ImageSegment(val meta: MediaMeta) : ContentSegment - data class VideoSegment(val meta: MediaMeta) : ContentSegment - data class AudioSegment(val meta: MediaMeta) : ContentSegment - data class UnknownMediaSegment(val meta: MediaMeta) : ContentSegment - data class LinkSegment(val url: String) : ContentSegment - data class InlineLinkSegment(val url: String) : ContentSegment - data class NostrNoteSegment(val eventId: String, val relayHints: List = emptyList()) : ContentSegment - data class NostrProfileSegment(val pubkey: String, val relayHints: List = emptyList()) : ContentSegment - data class NostrAddressableSegment(val dTag: String, val relays: List, val author: String?, val kind: Int?) : ContentSegment + + data class TextSegment(val text: String) : ContentSegment { + override fun toString(): String { + return text + } + } + data class ImageSegment(val meta: MediaMeta) : ContentSegment { + override fun toString(): String { + return meta.url + } + } + data class VideoSegment(val meta: MediaMeta) : ContentSegment { + override fun toString(): String { + return meta.url + } + } + data class AudioSegment(val meta: MediaMeta) : ContentSegment { + override fun toString(): String { + return meta.url + } + } + data class UnknownMediaSegment(val meta: MediaMeta) : ContentSegment { + override fun toString(): String { + return meta.url + } + } + data class LinkSegment(val url: String) : ContentSegment { + override fun toString(): String { + return url + } + } + data class InlineLinkSegment(val url: String) : ContentSegment { + override fun toString(): String { + return url + } + } + data class NostrNoteSegment(val eventId: String, val relayHints: List = emptyList()) : ContentSegment { + override fun toString(): String { + return NEvent.create( + idHex = eventId, + author = null, + kind = null, + relays = relayHints.map { it.normalizeRelayUrl() }, + ) + } + } + data class NostrProfileSegment(val pubkey: String, val relayHints: List = emptyList()) : ContentSegment { + override fun toString(): String { + return NProfile.create( + authorPubKeyHex = pubkey, + relays = relayHints.map { it.normalizeRelayUrl() } + ) + } + } + data class NostrAddressableSegment(val dTag: String, val relays: List, val author: String?, val kind: Int?) : ContentSegment { + override fun toString(): String { + return author?.let { + kind?.let { + NAddress.create( + kind = kind , + relays = relays.map { it.normalizeRelayUrl() }, + pubKeyHex = author, + dTag = dTag + ) + } + } ?: "Malformed naddress" + } + } data class CustomEmojiSegment(val shortcode: String, val url: String) : ContentSegment data class HashtagSegment(val tag: String) : ContentSegment data class LightningInvoiceSegment(val invoice: String, val decoded: Bolt11Invoice) : ContentSegment diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt index 262039db..8bc9ea9e 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt @@ -283,7 +283,6 @@ fun RichContent( if (localQuotedNostrEvent != null) { QuotedNote( localQuotedNostrEvent = localQuotedNostrEvent, - relayHints = segment.relayHints, onNoteClick = onNoteClick, noteActions = noteActions ) @@ -386,7 +385,7 @@ fun RichContent( // } else -> { Text( - text = "Unsupported Content" + text = segment.toString() ) } }