Simplifying Private message rendering scheme

This commit is contained in:
Vitor Pamplona
2023-05-25 20:39:15 -04:00
parent 07ccf75d44
commit fe317964b8
2 changed files with 10 additions and 5 deletions
@@ -39,7 +39,7 @@ class PrivateDmEvent(
fun with(pubkeyHex: String): Boolean { fun with(pubkeyHex: String): Boolean {
return pubkeyHex == pubKey || return pubkeyHex == pubKey ||
tags.firstOrNull { it.size > 1 && it[0] == "p" }?.getOrNull(1) == pubkeyHex tags.any { it.size > 1 && it[0] == "p" && it[1] == pubkeyHex }
} }
fun plainContent(privKey: ByteArray, pubKey: ByteArray): String? { fun plainContent(privKey: ByteArray, pubKey: ByteArray): String? {
@@ -567,13 +567,18 @@ private fun RenderPrivateMessage(
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val noteEvent = note.event as? PrivateDmEvent ?: return val noteEvent = note.event as? PrivateDmEvent ?: return
val withMe = remember { noteEvent.with(accountViewModel.userProfile().pubkeyHex) } val withMe = remember { noteEvent.with(accountViewModel.userProfile().pubkeyHex) }
val tags = remember(note.event?.id()) { note.event?.tags() }
val hashtags = remember(note.event?.id()) { note.event?.hashtags() ?: emptyList() }
val modifier = remember(note.event?.id()) { Modifier.fillMaxWidth() }
val isAuthorTheLoggedUser = remember(note.event?.id()) { accountViewModel.isLoggedUser(note.author) }
if (withMe) { if (withMe) {
val eventContent = remember { accountViewModel.decrypt(note) } val eventContent = remember { accountViewModel.decrypt(note) }
if (eventContent != null) { if (eventContent != null) {
if (makeItShort && accountViewModel.isLoggedUser(note.author)) { if (makeItShort && isAuthorTheLoggedUser) {
Text( Text(
text = eventContent, text = eventContent,
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f), color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
@@ -584,14 +589,14 @@ private fun RenderPrivateMessage(
TranslatableRichTextViewer( TranslatableRichTextViewer(
content = eventContent, content = eventContent,
canPreview = canPreview && !makeItShort, canPreview = canPreview && !makeItShort,
modifier = Modifier.fillMaxWidth(), modifier = modifier,
tags = noteEvent.tags(), tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav nav = nav
) )
DisplayUncitedHashtags(noteEvent.hashtags(), eventContent, nav) DisplayUncitedHashtags(hashtags, eventContent, nav)
} }
} }
} else { } else {