diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt index a114e3b3..2f811fe5 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt @@ -1,7 +1,6 @@ package ac.cord.auxiliary.compose.database.model.intermdiate import ac.cord.auxiliary.compose.database.model.Mention -import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Profile import androidx.room.Embedded import androidx.room.Relation diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentParser.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentParser.kt index 5482a277..75778ba1 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentParser.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/ContentParser.kt @@ -15,6 +15,7 @@ import com.vitorpamplona.quartz.nip19Bech32.entities.NAddress import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip19Bech32.entities.NNote import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile +import com.vitorpamplona.quartz.nip19Bech32.entities.NPub internal object ContentParser { @@ -62,6 +63,9 @@ internal object ContentParser { is NProfile -> { segments.add(ContentSegment.NostrProfileSegment(entity.hex, entity.relay.map { it.url })) } + is NPub -> { + segments.add(ContentSegment.NostrProfileSegment(pubkey = entity.hex)) + } is NNote -> { segments.add(ContentSegment.NostrNoteSegment(entity.hex)) } 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 f062ac13..072883b0 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 @@ -25,6 +25,7 @@ import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.withLink import androidx.compose.ui.text.withStyle +import co.touchlab.kermit.Logger import coil3.compose.AsyncImage @Composable @@ -49,6 +50,8 @@ fun RichContent( // val profileVer = eventRepo?.profileVersion?.collectAsState()?.value ?: 0 var fullScreenImageUrl by remember { mutableStateOf(null) } + Logger.withTag("RichContent").d("Segments: $segments") + if (fullScreenImageUrl != null) { FullScreenImageViewer( imageUrl = fullScreenImageUrl!!, @@ -79,7 +82,7 @@ fun RichContent( } } - val defaultLinkColor = MaterialTheme.colorScheme.primary + val defaultLinkColor = MaterialTheme.colorScheme.secondary val effectiveLinkColor = if (linkColor == Color.Unspecified) defaultLinkColor else linkColor val linkDecoration = if (linkColor == Color.Unspecified) TextDecoration.None else TextDecoration.Underline val uriHandler = LocalUriHandler.current @@ -99,13 +102,13 @@ fun RichContent( .map { it.pubkey } val profileNames = remember(profilePubkeys) { - // TODO: Get these from taggedUsers... val names = mutableMapOf() -// TODO for (pubkey in profilePubkeys) { -// val profile = localNostrEvent.mentionedProfiles.find { taggedAuthor -> taggedAuthor.publicKey == pubkey } -// names[pubkey] = profile?.humanReadableNameOrPubkey() -// ?: "${pubkey.take(8)}...${pubkey.takeLast(4)}" -// } + for (pubkey in profilePubkeys) { + + val mentionedProfile = localNostrEvent.mentionedProfiles.find { mentionedProfile -> mentionedProfile.profile?.publicKey == pubkey } + names[pubkey] = mentionedProfile?.profile?.humanReadableNameOrPubkey() + ?: "${pubkey.take(8)}...${pubkey.takeLast(4)}" + } names } // TODO Queue fetches for any missing profiles @@ -179,6 +182,7 @@ fun RichContent( } } is ContentSegment.NostrProfileSegment -> { + Logger.withTag("RichContent").d("NostrProfileSegment: $seg") val pubkey = seg.pubkey val displayName = profileNames[seg.pubkey] ?: seg.pubkey.take(8) withLink( @@ -224,13 +228,16 @@ fun RichContent( } } } - else -> {} + else -> { + Logger.withTag("RichContent").w("Unsupported segment: $seg") + } } } } Text(text = annotated, style = style, inlineContent = emojiInlineContent) } else { + Logger.w("Doing the else: $group") val segment = group as ContentSegment when (segment) { // is ContentSegment.ImageSegment -> { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt index af1c9c2e..bc67037f 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt @@ -4,6 +4,7 @@ import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent 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 ac.cord.auxiliary.compose.ui.theme.AuxTheme import androidx.compose.foundation.layout.Arrangement @@ -135,16 +136,14 @@ fun TextNoteEventDetail( ) } } - Text( + + RichContent( modifier = Modifier.fillMaxWidth().padding( horizontal = 20.dp ), - textAlign = TextAlign.Start, - text = localNostrEvent.nostrEvent.content + localNostrEvent = localNostrEvent, ) - - Row( modifier = Modifier.fillMaxWidth().padding(20.dp), horizontalArrangement = Arrangement.Start diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt index 343e7559..2c03455f 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt @@ -4,6 +4,7 @@ import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent 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 ac.cord.auxiliary.compose.ui.theme.AuxTheme import androidx.compose.foundation.clickable @@ -176,13 +177,9 @@ private fun TextNoteFeedItem( ) } - // TODO: RichContent here... -// RichContent( -// modifier = Modifier.fillMaxWidth(), -// localNostrEvent = localNostrEvent, -// ) - Text( - text = localNostrEvent.nostrEvent.content + RichContent( + modifier = Modifier.fillMaxWidth(), + localNostrEvent = localNostrEvent, ) LazyRow(