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
fun DisplayUncitedHashtags(
event: Event,
callbackUri: String? = null,
nav: (String) -> Unit,
) {
DisplayUncitedHashtags(event, event.content, nav)
DisplayUncitedHashtags(event, event.content, callbackUri, nav)
}
@OptIn(ExperimentalLayoutApi::class)
@@ -52,6 +53,7 @@ fun DisplayUncitedHashtags(
fun DisplayUncitedHashtags(
event: Event,
content: String,
callbackUri: String? = null,
nav: (String) -> Unit,
) {
val unusedHashtags by
@@ -59,7 +61,7 @@ fun DisplayUncitedHashtags(
val tagsInEvent = event.hashtags()
if (tagsInEvent.isNotEmpty()) {
launch(Dispatchers.Default) {
val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists())
val state = CachedRichTextParser.parseText(content, event.tags.toImmutableListOfLists(), callbackUri)
val tagsInContent =
state
@@ -216,6 +216,8 @@ fun AudioHeader(
}
}
val callbackUri = remember(note) { note.toNostrUri() }
content?.let {
Row(
verticalAlignment = Alignment.CenterVertically,
@@ -231,7 +233,7 @@ fun AudioHeader(
tags = tags,
backgroundColor = background,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -240,7 +242,7 @@ fun AudioHeader(
if (noteEvent.hasHashtags()) {
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
DisplayUncitedHashtags(noteEvent, nav)
DisplayUncitedHashtags(noteEvent, callbackUri, nav)
}
}
}
@@ -170,23 +170,23 @@ private fun RenderGitPatchEvent(
overflow = TextOverflow.Ellipsis,
)
} else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
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(
content = eventContent,
canPreview = canPreview && !makeItShort,
quotesLeft = quotesLeft,
modifier = modifier,
modifier = Modifier.fillMaxWidth(),
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -196,6 +196,7 @@ private fun RenderGitPatchEvent(
DisplayUncitedHashtags(
event = noteEvent,
content = eventContent,
callbackUri = callbackUri,
nav = nav,
)
}
@@ -274,11 +275,12 @@ private fun RenderGitIssueEvent(
overflow = TextOverflow.Ellipsis,
)
} else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
accountViewModel = accountViewModel,
) {
val modifier = remember(note) { Modifier.fillMaxWidth() }
val tags =
remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
@@ -286,18 +288,18 @@ private fun RenderGitIssueEvent(
content = eventContent,
canPreview = canPreview && !makeItShort,
quotesLeft = quotesLeft,
modifier = modifier,
modifier = Modifier.fillMaxWidth(),
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
}
if (note.event?.hasHashtags() == true) {
DisplayUncitedHashtags(noteEvent, eventContent, nav)
DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
}
}
}
@@ -47,6 +47,7 @@ fun RenderNIP90ContentDiscoveryResponse(
nav: (String) -> Unit,
) {
val noteEvent = note.event as? NIP90ContentDiscoveryResponseEvent ?: return
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
@@ -64,13 +65,13 @@ fun RenderNIP90ContentDiscoveryResponse(
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
}
if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, noteEvent.content, nav)
DisplayUncitedHashtags(noteEvent, noteEvent.content, callbackUri, nav)
}
}
@@ -97,6 +97,7 @@ fun RenderPoll(
)
} else {
val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
@@ -110,7 +111,7 @@ fun RenderPoll(
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -125,7 +126,7 @@ fun RenderPoll(
}
if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav)
DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
}
}
}
@@ -101,6 +101,8 @@ fun RenderPrivateMessage(
overflow = TextOverflow.Ellipsis,
)
} else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
accountViewModel = accountViewModel,
@@ -113,14 +115,14 @@ fun RenderPrivateMessage(
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
}
if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav)
DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
}
}
}
@@ -128,6 +128,8 @@ fun RenderTextEvent(
overflow = TextOverflow.Ellipsis,
)
} else {
val callbackUri = remember(note) { note.toNostrUri() }
SensitivityWarning(
note = note,
accountViewModel = accountViewModel,
@@ -150,14 +152,14 @@ fun RenderTextEvent(
} else {
note.idHex
},
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
}
if (noteEvent.hasHashtags()) {
DisplayUncitedHashtags(noteEvent, eventContent, nav)
DisplayUncitedHashtags(noteEvent, eventContent, callbackUri, nav)
}
}
}
@@ -165,6 +165,8 @@ fun VideoDisplay(
}
summary?.let {
val callbackUri = remember(note) { note.toNostrUri() }
TranslatableRichTextViewer(
content = it,
canPreview = canPreview && !makeItShort,
@@ -173,7 +175,7 @@ fun VideoDisplay(
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
callbackUri = note.toNostrUri(),
callbackUri = callbackUri,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -182,7 +184,7 @@ fun VideoDisplay(
Row(
Modifier.fillMaxWidth(),
) {
DisplayUncitedHashtags(event, summary, nav)
DisplayUncitedHashtags(event, summary, callbackUri, nav)
}
}
}