Add toString for contentSegment
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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<String> = emptyList()) : ContentSegment
|
||||
data class NostrProfileSegment(val pubkey: String, val relayHints: List<String> = emptyList()) : ContentSegment
|
||||
data class NostrAddressableSegment(val dTag: String, val relays: List<String>, 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<String> = 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<String> = 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<String>, 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
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user