Unpacking replies in Quotes.

This commit is contained in:
Vitor Pamplona
2023-02-27 17:14:15 -05:00
parent 4c916c7957
commit 254ed99625
3 changed files with 60 additions and 26 deletions
@@ -88,7 +88,7 @@ fun RichTextViewer(
} else if (noProtocolUrlValidator.matcher(word).matches()) { } else if (noProtocolUrlValidator.matcher(word).matches()) {
UrlPreview("https://$word", word) UrlPreview("https://$word", word)
} else if (tagIndex.matcher(word).matches() && tags != null) { } 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)) { } else if (isBechLink(word)) {
BechLink(word, navController) BechLink(word, navController)
} else { } else {
@@ -107,7 +107,7 @@ fun RichTextViewer(
} else if (noProtocolUrlValidator.matcher(word).matches()) { } else if (noProtocolUrlValidator.matcher(word).matches()) {
ClickableUrl(word, "https://$word") ClickableUrl(word, "https://$word")
} else if (tagIndex.matcher(word).matches() && tags != null) { } 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)) { } else if (isBechLink(word)) {
BechLink(word, navController) BechLink(word, navController)
} else { } else {
@@ -161,7 +161,7 @@ fun BechLink(word: String, navController: NavController) {
@Composable @Composable
fun TagLink(word: String, tags: List<List<String>>, backgroundColor: Color, accountViewModel: AccountViewModel, navController: NavController) { fun TagLink(word: String, tags: List<List<String>>, canPreview: Boolean, backgroundColor: Color, accountViewModel: AccountViewModel, navController: NavController) {
val matcher = tagIndex.matcher(word) val matcher = tagIndex.matcher(word)
val index = try { val index = try {
@@ -194,22 +194,27 @@ fun TagLink(word: String, tags: List<List<String>>, backgroundColor: Color, acco
} else if (tags[index][0] == "e") { } else if (tags[index][0] == "e") {
val note = LocalCache.checkGetOrCreateNote(tags[index][1]) val note = LocalCache.checkGetOrCreateNote(tags[index][1])
if (note != null) { if (note != null) {
//ClickableNoteTag(note, navController) if (canPreview) {
NoteCompose( NoteCompose(
baseNote = note, baseNote = note,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
modifier = Modifier modifier = Modifier
.padding(0.dp) .padding(0.dp)
.fillMaxWidth() .fillMaxWidth()
.clip(shape = RoundedCornerShape(15.dp)) .clip(shape = RoundedCornerShape(15.dp))
.border( .border(
1.dp, 1.dp,
MaterialTheme.colors.onSurface.copy(alpha = 0.12f), MaterialTheme.colors.onSurface.copy(alpha = 0.12f),
RoundedCornerShape(15.dp) RoundedCornerShape(15.dp)
), ),
parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f).compositeOver(backgroundColor), parentBackgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f)
isQuotedNote = true, .compositeOver(backgroundColor),
navController = navController) isQuotedNote = true,
navController = navController
)
} else {
ClickableNoteTag(note, navController)
}
} else { } else {
// if here the tag is not a valid Nostr Hex // if here the tag is not a valid Nostr Hex
Text(text = "$word ") Text(text = "$word ")
@@ -1,9 +1,9 @@
package com.vitorpamplona.amethyst.ui.note package com.vitorpamplona.amethyst.ui.note
import android.util.Log
import androidx.compose.foundation.* import androidx.compose.foundation.*
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ExpandMore 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.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.Following import com.vitorpamplona.amethyst.ui.theme.Following
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
import nostr.postr.events.TextNoteEvent import nostr.postr.events.TextNoteEvent
@OptIn(ExperimentalFoundationApi::class, ExperimentalTime::class, ExperimentalTime::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun NoteCompose( fun NoteCompose(
baseNote: Note, baseNote: Note,
@@ -56,6 +55,8 @@ fun NoteCompose(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
isBoostedNote: Boolean = false, isBoostedNote: Boolean = false,
isQuotedNote: Boolean = false, isQuotedNote: Boolean = false,
unPackReply: Boolean = true,
makeItShort: Boolean = false,
parentBackgroundColor: Color? = null, parentBackgroundColor: Color? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
navController: NavController navController: NavController
@@ -253,11 +254,36 @@ fun NoteCompose(
} }
} }
if (note.author != null) if (note.author != null && !makeItShort) {
ObserveDisplayNip05Status(note.author!!) ObserveDisplayNip05Status(note.author!!)
}
Spacer(modifier = Modifier.height(3.dp))
if (noteEvent is TextNoteEvent && (note.replyTo != null || note.mentions != null)) { 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)) { } else if (noteEvent is ChannelMessageEvent && (note.replyTo != null || note.mentions != null)) {
val sortedMentions = note.mentions?.toSet()?.sortedBy { account.userProfile().isFollowing(it) } val sortedMentions = note.mentions?.toSet()?.sortedBy { account.userProfile().isFollowing(it) }
@@ -272,6 +298,7 @@ fun NoteCompose(
it, it,
modifier = Modifier, modifier = Modifier,
isBoostedNote = true, isBoostedNote = true,
unPackReply = false,
parentBackgroundColor = backgroundColor, parentBackgroundColor = backgroundColor,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
navController = navController navController = navController
@@ -315,7 +342,7 @@ fun NoteCompose(
if (eventContent != null) { if (eventContent != null) {
TranslateableRichTextViewer( TranslateableRichTextViewer(
eventContent, eventContent,
canPreview, canPreview = canPreview && !makeItShort,
Modifier.fillMaxWidth(), Modifier.fillMaxWidth(),
noteEvent.tags, noteEvent.tags,
backgroundColor, backgroundColor,
@@ -324,7 +351,8 @@ fun NoteCompose(
) )
} }
ReactionsRow(note, accountViewModel) if (!makeItShort)
ReactionsRow(note, accountViewModel)
Divider( Divider(
modifier = Modifier.padding(top = 10.dp), modifier = Modifier.padding(top = 10.dp),
@@ -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, parentBackgroundColor = if (item.idHex == noteId) MaterialTheme.colors.primary.copy(0.12f).compositeOver(MaterialTheme.colors.background) else null,
isBoostedNote = false, isBoostedNote = false,
unPackReply = false,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
navController = navController, navController = navController,
) )