Minor refactoring

This commit is contained in:
Vitor Pamplona
2024-04-02 09:42:01 -04:00
parent 4380393c5b
commit c7563c938d
3 changed files with 9 additions and 22 deletions

View File

@@ -2353,7 +2353,7 @@ class Account(
} else if (event is LnZapRequestEvent && event.isPrivateZap() && isWriteable()) { } else if (event is LnZapRequestEvent && event.isPrivateZap() && isWriteable()) {
event.cachedPrivateZap()?.content event.cachedPrivateZap()?.content
} else { } else {
event?.content() event.content()
} }
} }

View File

@@ -466,13 +466,9 @@ private fun NoteRow(
) { ) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
when (note.event) { when (note.event) {
is ChannelCreateEvent -> { is ChannelCreateEvent -> RenderCreateChannelNote(note)
RenderCreateChannelNote(note) is ChannelMetadataEvent -> RenderChangeChannelMetadataNote(note)
} is DraftEvent ->
is ChannelMetadataEvent -> {
RenderChangeChannelMetadataNote(note)
}
is DraftEvent -> {
RenderDraftEvent( RenderDraftEvent(
note, note,
canPreview, canPreview,
@@ -483,8 +479,7 @@ private fun NoteRow(
accountViewModel, accountViewModel,
nav, nav,
) )
} else ->
else -> {
RenderRegularTextNote( RenderRegularTextNote(
note, note,
canPreview, canPreview,
@@ -493,7 +488,6 @@ private fun NoteRow(
accountViewModel, accountViewModel,
nav, nav,
) )
}
} }
} }
} }

View File

@@ -25,6 +25,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@@ -70,19 +71,11 @@ fun LoadDecryptedContentOrNull(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
inner: @Composable (String?) -> Unit, inner: @Composable (String?) -> Unit,
) { ) {
var decryptedContent by val decryptedContent by
remember(note.event) { produceState(initialValue = accountViewModel.cachedDecrypt(note), key1 = note.event?.id()) {
mutableStateOf( accountViewModel.decrypt(note) { value = it }
accountViewModel.cachedDecrypt(note),
)
} }
if (decryptedContent == null) {
LaunchedEffect(key1 = decryptedContent) {
accountViewModel.decrypt(note) { decryptedContent = it }
}
}
inner(decryptedContent) inner(decryptedContent)
} }