From 254ed9962568493c2a6bfc8cdf50e7efdbfa9494 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 27 Feb 2023 17:14:15 -0500 Subject: [PATCH] Unpacking replies in Quotes. --- .../amethyst/ui/components/RichTextViewer.kt | 43 +++++++++++-------- .../amethyst/ui/note/NoteCompose.kt | 42 +++++++++++++++--- .../amethyst/ui/screen/ThreadFeedView.kt | 1 + 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt index 2e0c6f7b9..6aa1edb8f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt @@ -88,7 +88,7 @@ fun RichTextViewer( } else if (noProtocolUrlValidator.matcher(word).matches()) { UrlPreview("https://$word", word) } else if (tagIndex.matcher(word).matches() && tags != null) { - TagLink(word, tags, backgroundColor, accountViewModel, navController) + TagLink(word, tags, canPreview, backgroundColor, accountViewModel, navController) } else if (isBechLink(word)) { BechLink(word, navController) } else { @@ -107,7 +107,7 @@ fun RichTextViewer( } else if (noProtocolUrlValidator.matcher(word).matches()) { ClickableUrl(word, "https://$word") } else if (tagIndex.matcher(word).matches() && tags != null) { - TagLink(word, tags, backgroundColor, accountViewModel, navController) + TagLink(word, tags, canPreview, backgroundColor, accountViewModel, navController) } else if (isBechLink(word)) { BechLink(word, navController) } else { @@ -161,7 +161,7 @@ fun BechLink(word: String, navController: NavController) { @Composable -fun TagLink(word: String, tags: List>, backgroundColor: Color, accountViewModel: AccountViewModel, navController: NavController) { +fun TagLink(word: String, tags: List>, canPreview: Boolean, backgroundColor: Color, accountViewModel: AccountViewModel, navController: NavController) { val matcher = tagIndex.matcher(word) val index = try { @@ -194,22 +194,27 @@ fun TagLink(word: String, tags: List>, backgroundColor: Color, acco } else if (tags[index][0] == "e") { val note = LocalCache.checkGetOrCreateNote(tags[index][1]) if (note != null) { - //ClickableNoteTag(note, navController) - NoteCompose( - baseNote = note, - accountViewModel = accountViewModel, - modifier = Modifier - .padding(0.dp) - .fillMaxWidth() - .clip(shape = RoundedCornerShape(15.dp)) - .border( - 1.dp, - MaterialTheme.colors.onSurface.copy(alpha = 0.12f), - RoundedCornerShape(15.dp) - ), - parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f).compositeOver(backgroundColor), - isQuotedNote = true, - navController = navController) + if (canPreview) { + NoteCompose( + baseNote = note, + accountViewModel = accountViewModel, + modifier = Modifier + .padding(0.dp) + .fillMaxWidth() + .clip(shape = RoundedCornerShape(15.dp)) + .border( + 1.dp, + MaterialTheme.colors.onSurface.copy(alpha = 0.12f), + RoundedCornerShape(15.dp) + ), + parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f) + .compositeOver(backgroundColor), + isQuotedNote = true, + navController = navController + ) + } else { + ClickableNoteTag(note, navController) + } } else { // if here the tag is not a valid Nostr Hex Text(text = "$word ") diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index 1618766b4..368c32ea4 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -1,9 +1,9 @@ package com.vitorpamplona.amethyst.ui.note -import android.util.Log import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ExpandMore @@ -45,10 +45,9 @@ import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.Following import kotlin.time.ExperimentalTime -import kotlin.time.measureTimedValue import nostr.postr.events.TextNoteEvent -@OptIn(ExperimentalFoundationApi::class, ExperimentalTime::class, ExperimentalTime::class) +@OptIn(ExperimentalFoundationApi::class) @Composable fun NoteCompose( baseNote: Note, @@ -56,6 +55,8 @@ fun NoteCompose( modifier: Modifier = Modifier, isBoostedNote: Boolean = false, isQuotedNote: Boolean = false, + unPackReply: Boolean = true, + makeItShort: Boolean = false, parentBackgroundColor: Color? = null, accountViewModel: AccountViewModel, navController: NavController @@ -253,11 +254,36 @@ fun NoteCompose( } } - if (note.author != null) + if (note.author != null && !makeItShort) { ObserveDisplayNip05Status(note.author!!) + } + + Spacer(modifier = Modifier.height(3.dp)) if (noteEvent is TextNoteEvent && (note.replyTo != null || note.mentions != null)) { - ReplyInformation(note.replyTo, note.mentions, account, navController) + val replyingDirectlyTo = note.replyTo?.lastOrNull() + if (replyingDirectlyTo != null && unPackReply) { + NoteCompose( + baseNote = replyingDirectlyTo, + isQuotedNote = true, + modifier = Modifier + .padding(0.dp) + .fillMaxWidth() + .clip(shape = RoundedCornerShape(15.dp)) + .border( + 1.dp, + MaterialTheme.colors.onSurface.copy(alpha = 0.12f), + RoundedCornerShape(15.dp) + ), + unPackReply = false, + makeItShort = true, + parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f).compositeOver(backgroundColor), + accountViewModel = accountViewModel, + navController = navController + ) + } else { + ReplyInformation(note.replyTo, note.mentions, account, navController) + } } else if (noteEvent is ChannelMessageEvent && (note.replyTo != null || note.mentions != null)) { val sortedMentions = note.mentions?.toSet()?.sortedBy { account.userProfile().isFollowing(it) } @@ -272,6 +298,7 @@ fun NoteCompose( it, modifier = Modifier, isBoostedNote = true, + unPackReply = false, parentBackgroundColor = backgroundColor, accountViewModel = accountViewModel, navController = navController @@ -315,7 +342,7 @@ fun NoteCompose( if (eventContent != null) { TranslateableRichTextViewer( eventContent, - canPreview, + canPreview = canPreview && !makeItShort, Modifier.fillMaxWidth(), noteEvent.tags, backgroundColor, @@ -324,7 +351,8 @@ fun NoteCompose( ) } - ReactionsRow(note, accountViewModel) + if (!makeItShort) + ReactionsRow(note, accountViewModel) Divider( modifier = Modifier.padding(top = 10.dp), diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt index 44c7a90f0..2f46795a7 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt @@ -132,6 +132,7 @@ fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: A ), parentBackgroundColor = if (item.idHex == noteId) MaterialTheme.colors.primary.copy(0.12f).compositeOver(MaterialTheme.colors.background) else null, isBoostedNote = false, + unPackReply = false, accountViewModel = accountViewModel, navController = navController, )