Add toString for contentSegment
This commit is contained in:
1 parent
755e91bbd5
commit
ab85352bfb
3 files changed
+78
-21
No files matched your search
+5
-9
@@ -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.Profile
|
||||||
import ac.cord.auxiliary.compose.database.model.QuotedRelation
|
import ac.cord.auxiliary.compose.database.model.QuotedRelation
|
||||||
import ac.cord.auxiliary.compose.extensions.toFormattedTimeAndDateString
|
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.composable.widgets.profile.ProfileAvatar
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -76,15 +77,10 @@ data class LocalQuotedNostrEvent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use RichContent...
|
RichContent(
|
||||||
Text(
|
nostrEvent = nostrEvent,
|
||||||
modifier = Modifier.fillMaxWidth().padding(
|
localQuotedNostrEvent = null,
|
||||||
horizontal = 20.dp
|
mentionedProfiles = mentionedProfiles,
|
||||||
),
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
textAlign = TextAlign.Start,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
text = nostrEvent.content
|
|
||||||
)
|
)
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
||||||
|
|||||||
+72
-10
@@ -1,18 +1,80 @@
|
|||||||
package ac.cord.auxiliary.compose.ui.composable.widgets.content
|
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
|
import fr.acinq.lightning.payment.Bolt11Invoice
|
||||||
|
|
||||||
internal sealed interface ContentSegment {
|
internal sealed interface ContentSegment {
|
||||||
data class TextSegment(val text: String) : ContentSegment
|
|
||||||
data class ImageSegment(val meta: MediaMeta) : ContentSegment
|
data class TextSegment(val text: String) : ContentSegment {
|
||||||
data class VideoSegment(val meta: MediaMeta) : ContentSegment
|
override fun toString(): String {
|
||||||
data class AudioSegment(val meta: MediaMeta) : ContentSegment
|
return text
|
||||||
data class UnknownMediaSegment(val meta: MediaMeta) : ContentSegment
|
}
|
||||||
data class LinkSegment(val url: String) : ContentSegment
|
}
|
||||||
data class InlineLinkSegment(val url: String) : ContentSegment
|
data class ImageSegment(val meta: MediaMeta) : ContentSegment {
|
||||||
data class NostrNoteSegment(val eventId: String, val relayHints: List<String> = emptyList()) : ContentSegment
|
override fun toString(): String {
|
||||||
data class NostrProfileSegment(val pubkey: String, val relayHints: List<String> = emptyList()) : ContentSegment
|
return meta.url
|
||||||
data class NostrAddressableSegment(val dTag: String, val relays: List<String>, val author: String?, val kind: Int?) : ContentSegment
|
}
|
||||||
|
}
|
||||||
|
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 CustomEmojiSegment(val shortcode: String, val url: String) : ContentSegment
|
||||||
data class HashtagSegment(val tag: String) : ContentSegment
|
data class HashtagSegment(val tag: String) : ContentSegment
|
||||||
data class LightningInvoiceSegment(val invoice: String, val decoded: Bolt11Invoice) : ContentSegment
|
data class LightningInvoiceSegment(val invoice: String, val decoded: Bolt11Invoice) : ContentSegment
|
||||||
|
|||||||
+1
-2
@@ -283,7 +283,6 @@ fun RichContent(
|
|||||||
if (localQuotedNostrEvent != null) {
|
if (localQuotedNostrEvent != null) {
|
||||||
QuotedNote(
|
QuotedNote(
|
||||||
localQuotedNostrEvent = localQuotedNostrEvent,
|
localQuotedNostrEvent = localQuotedNostrEvent,
|
||||||
relayHints = segment.relayHints,
|
|
||||||
onNoteClick = onNoteClick,
|
onNoteClick = onNoteClick,
|
||||||
noteActions = noteActions
|
noteActions = noteActions
|
||||||
)
|
)
|
||||||
@@ -386,7 +385,7 @@ fun RichContent(
|
|||||||
// }
|
// }
|
||||||
else -> {
|
else -> {
|
||||||
Text(
|
Text(
|
||||||
text = "Unsupported Content"
|
text = segment.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user