Adds the callbackUri to the display uncited hashtags so that it can reuse the previously parsed post.

This commit is contained in:
Vitor Pamplona
2024-07-31 10:18:23 -04:00
parent 231af1d3d8
commit 2b2f04f724
8 changed files with 37 additions and 23 deletions
@@ -42,9 +42,10 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun DisplayUncitedHashtags( fun DisplayUncitedHashtags(
event: Event, event: Event,
callbackUri: String? = null,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
DisplayUncitedHashtags(event, event.content, nav) DisplayUncitedHashtags(event, event.content, callbackUri, nav)
} }
@OptIn(ExperimentalLayoutApi::class) @OptIn(ExperimentalLayoutApi::class)
@@ -52,6 +53,7 @@ fun DisplayUncitedHashtags(
fun DisplayUncitedHashtags( fun DisplayUncitedHashtags(
event: Event, event: Event,
content: String, content: String,
callbackUri: String? = null,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val unusedHashtags by val unusedHashtags by
@@ -59,7 +61,7 @@ fun DisplayUncitedHashtags(
val tagsInEvent = event.hashtags() val tagsInEvent = event.hashtags()
if (tagsInEvent.isNotEmpty()) { if (tagsInEvent.isNotEmpty()) {
launch(Dispatchers.Default) { launch(Dispatchers.Default) {
val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists()) val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists(), callbackUri)
val tagsInContent = val tagsInContent =
state state
@@ -216,6 +216,8 @@ fun AudioHeader(
} }
} }
val callbackUri = remember(note) { note.toNostrUri() }
content?.let { content?.let {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@@ -231,7 +233,7 @@ fun AudioHeader(
tags = tags, tags = tags,
backgroundColor = background, backgroundColor = background,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -240,7 +242,7 @@ fun AudioHeader(
if (noteEvent.hasHashtags()) { if (noteEvent.hasHashtags()) {
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
DisplayUncitedHashtags(noteEvent, nav) DisplayUncitedHashtags(noteEvent, callbackUri, nav)
} }
} }
} }
@@ -170,23 +170,23 @@ private fun RenderGitPatchEvent(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} else { } else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
val modifier = remember(note) { Modifier.fillMaxWidth() } val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
val tags =
remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
TranslatableRichTextViewer( TranslatableRichTextViewer(
content = eventContent, content = eventContent,
canPreview = canPreview && !makeItShort, canPreview = canPreview && !makeItShort,
quotesLeft = quotesLeft, quotesLeft = quotesLeft,
modifier = modifier, modifier = Modifier.fillMaxWidth(),
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -196,6 +196,7 @@ private fun RenderGitPatchEvent(
DisplayUncitedHashtags( DisplayUncitedHashtags(
event = noteEvent, event = noteEvent,
content = eventContent, content = eventContent,
callbackUri = callbackUri,
nav = nav, nav = nav,
) )
} }
@@ -274,11 +275,12 @@ private fun RenderGitIssueEvent(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} else { } else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
val modifier = remember(note) { Modifier.fillMaxWidth() }
val tags = val tags =
remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList } remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
@@ -286,18 +288,18 @@ private fun RenderGitIssueEvent(
content = eventContent, content = eventContent,
canPreview = canPreview && !makeItShort, canPreview = canPreview && !makeItShort,
quotesLeft = quotesLeft, quotesLeft = quotesLeft,
modifier = modifier, modifier = Modifier.fillMaxWidth(),
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
} }
if (note.event?.hasHashtags() == true) { if (note.event?.hasHashtags() == true) {
DisplayUncitedHashtags(noteEvent, eventContent, nav) DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
} }
} }
} }
@@ -47,6 +47,7 @@ fun RenderNIP90ContentDiscoveryResponse(
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val noteEvent = note.event as? NIP90ContentDiscoveryResponseEvent ?: return val noteEvent = note.event as? NIP90ContentDiscoveryResponseEvent ?: return
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
@@ -64,13 +65,13 @@ fun RenderNIP90ContentDiscoveryResponse(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
} }
if (noteEvent.hasHashtags()) { if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, noteEvent.content, nav) DisplayUncitedHashtags(noteEvent, noteEvent.content, callbackUri, nav)
} }
} }
@@ -97,6 +97,7 @@ fun RenderPoll(
) )
} else { } else {
val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList } val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
@@ -110,7 +111,7 @@ fun RenderPoll(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -125,7 +126,7 @@ fun RenderPoll(
} }
if (noteEvent.hasHashtags()) { if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav) DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
} }
} }
} }
@@ -101,6 +101,8 @@ fun RenderPrivateMessage(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} else { } else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
@@ -113,14 +115,14 @@ fun RenderPrivateMessage(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
} }
if (noteEvent.hasHashtags()) { if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav) DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
} }
} }
} }
@@ -128,6 +128,8 @@ fun RenderTextEvent(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} else { } else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning( SensitivityWarning(
note = note, note = note,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
@@ -150,14 +152,14 @@ fun RenderTextEvent(
} else { } else {
note.idHex note.idHex
}, },
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
} }
if (noteEvent.hasHashtags()) { if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav) DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
} }
} }
} }
@@ -165,6 +165,8 @@ fun VideoDisplay(
} }
summary?.let { summary?.let {
val callbackUri = remember(note) { note.toNostrUri() }
TranslatableRichTextViewer( TranslatableRichTextViewer(
content = it, content = it,
canPreview = canPreview && !makeItShort, canPreview = canPreview && !makeItShort,
@@ -173,7 +175,7 @@ fun VideoDisplay(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(), callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -182,7 +184,7 @@ fun VideoDisplay(
Row( Row(
Modifier.fillMaxWidth(), Modifier.fillMaxWidth(),
) { ) {
DisplayUncitedHashtags(event, summary, nav) DisplayUncitedHashtags(event, summary, callbackUri, nav)
} }
} }
} }