Show mentions in text
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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<String?>(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<String, String>()
|
||||
// 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 -> {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user