Adds the post highlighted to the highlight display

This commit is contained in:
Vitor Pamplona
2023-07-14 09:04:34 -04:00
parent a86cd8772f
commit 640b0d3174
3 changed files with 54 additions and 9 deletions
@@ -20,6 +20,8 @@ class HighlightEvent(
fun author() = taggedUsers().firstOrNull() fun author() = taggedUsers().firstOrNull()
fun quote() = content fun quote() = content
fun inPost() = taggedAddresses().firstOrNull()
companion object { companion object {
const val kind = 9802 const val kind = 9802
@@ -130,6 +130,7 @@ import com.vitorpamplona.amethyst.ui.components.ClickableUrl
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.LoadThumbAndThenVideoView import com.vitorpamplona.amethyst.ui.components.LoadThumbAndThenVideoView
import com.vitorpamplona.amethyst.ui.components.MeasureSpaceWidth
import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
@@ -1441,11 +1442,15 @@ private fun RenderHighlight(
val url = remember() { val url = remember() {
(note.event as? HighlightEvent)?.inUrl() (note.event as? HighlightEvent)?.inUrl()
} }
val postHex = remember() {
(note.event as? HighlightEvent)?.taggedAddresses()?.firstOrNull()
}
DisplayHighlight( DisplayHighlight(
quote, quote,
author, author,
url, url,
postHex,
makeItShort, makeItShort,
canPreview, canPreview,
backgroundColor, backgroundColor,
@@ -2444,7 +2449,7 @@ fun MoreOptionsButton(
popupExpanded, popupExpanded,
accountViewModel accountViewModel
) )
} }
} }
@Composable @Composable
@@ -2620,6 +2625,7 @@ fun DisplayHighlight(
highlight: String, highlight: String,
authorHex: String?, authorHex: String?,
url: String?, url: String?,
postAddress: ATag?,
makeItShort: Boolean, makeItShort: Boolean,
canPreview: Boolean, canPreview: Boolean,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
@@ -2644,13 +2650,15 @@ fun DisplayHighlight(
nav nav
) )
DisplayQuoteAuthor(authorHex ?: "", url, nav) DisplayQuoteAuthor(authorHex ?: "", url, postAddress, accountViewModel, nav)
} }
@Composable @Composable
private fun DisplayQuoteAuthor( private fun DisplayQuoteAuthor(
authorHex: String, authorHex: String,
url: String?, url: String?,
postAddress: ATag?,
accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
var userBase by remember { mutableStateOf<User?>(LocalCache.getUserIfExists(authorHex)) } var userBase by remember { mutableStateOf<User?>(LocalCache.getUserIfExists(authorHex)) }
@@ -2666,13 +2674,47 @@ private fun DisplayQuoteAuthor(
} }
} }
Row { MeasureSpaceWidth {
userBase?.let { userBase -> Row(horizontalArrangement = Arrangement.spacedBy(it), verticalAlignment = Alignment.CenterVertically) {
LoadAndDisplayUser(userBase, nav) userBase?.let { userBase ->
} LoadAndDisplayUser(userBase, nav)
}
url?.let { url -> url?.let { url ->
LoadAndDisplayUrl(url) LoadAndDisplayUrl(url)
}
postAddress?.let { address ->
LoadAndDisplayPost(address, accountViewModel, nav)
}
}
}
}
@Composable
private fun LoadAndDisplayPost(postAddress: ATag, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
LoadAddressableNote(aTag = postAddress) {
it?.let { note ->
val noteEvent by note.live().metadata.map {
it.note.event
}.distinctUntilChanged().observeAsState(note.event)
val title = remember(noteEvent) {
(noteEvent as? LongTextNoteEvent)?.title()
}
title?.let {
Text(remember { "-" }, maxLines = 1)
ClickableText(
text = AnnotatedString(title),
onClick = {
routeFor(note, accountViewModel.userProfile())?.let {
nav(it)
}
},
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.primary)
)
}
} }
} }
} }
@@ -2689,7 +2731,7 @@ private fun LoadAndDisplayUrl(url: String) {
} }
validatedUrl?.host?.let { host -> validatedUrl?.host?.let { host ->
Text(remember { "on " }, maxLines = 1) Text(remember { "-" }, maxLines = 1)
ClickableUrl(urlText = host, url = url) ClickableUrl(urlText = host, url = url)
} }
} }
@@ -414,6 +414,7 @@ fun NoteMaster(
noteEvent.quote(), noteEvent.quote(),
noteEvent.author(), noteEvent.author(),
noteEvent.inUrl(), noteEvent.inUrl(),
noteEvent.inPost(),
false, false,
true, true,
backgroundColor, backgroundColor,