Cache zap calculations in notification cards.
This commit is contained in:
@@ -176,7 +176,9 @@ private fun Galeries(
|
||||
|
||||
if (hasZapEvents) {
|
||||
var zapEvents by remember(multiSetCard.zapEvents) {
|
||||
mutableStateOf<ImmutableList<ZapAmountCommentNotification>>(persistentListOf())
|
||||
mutableStateOf(
|
||||
accountViewModel.cachedDecryptAmountMessageInGroup(multiSetCard.zapEvents)
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(key1 = Unit) {
|
||||
|
||||
@@ -453,7 +453,7 @@ private fun WatchZapAndRenderGallery(
|
||||
val zapsState by baseNote.live().zaps.observeAsState()
|
||||
|
||||
var zapEvents by remember(zapsState) {
|
||||
mutableStateOf<ImmutableList<ZapAmountCommentNotification>>(
|
||||
mutableStateOf(
|
||||
accountViewModel.cachedDecryptAmountMessageInGroup(baseNote)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -248,6 +248,34 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
||||
}
|
||||
}
|
||||
|
||||
fun cachedDecryptAmountMessageInGroup(zapNotes: List<CombinedZap>): ImmutableList<ZapAmountCommentNotification> {
|
||||
return zapNotes.map {
|
||||
val request = it.request.event as? LnZapRequestEvent
|
||||
if (request?.isPrivateZap() == true) {
|
||||
val cachedPrivateRequest = request.cachedPrivateZap()
|
||||
if (cachedPrivateRequest != null) {
|
||||
ZapAmountCommentNotification(
|
||||
LocalCache.getUserIfExists(cachedPrivateRequest.pubKey) ?: it.request.author,
|
||||
cachedPrivateRequest.content.ifBlank { null },
|
||||
showAmountAxis((it.response.event as? LnZapEvent)?.amount)
|
||||
)
|
||||
} else {
|
||||
ZapAmountCommentNotification(
|
||||
it.request.author,
|
||||
it.request.event?.content()?.ifBlank { null },
|
||||
showAmountAxis((it.response.event as? LnZapEvent)?.amount)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
ZapAmountCommentNotification(
|
||||
it.request.author,
|
||||
it.request.event?.content()?.ifBlank { null },
|
||||
showAmountAxis((it.response.event as? LnZapEvent)?.amount)
|
||||
)
|
||||
}
|
||||
}.toImmutableList()
|
||||
}
|
||||
|
||||
fun cachedDecryptAmountMessageInGroup(baseNote: Note): ImmutableList<ZapAmountCommentNotification> {
|
||||
val myList = baseNote.zaps.toList()
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ import com.vitorpamplona.amethyst.ui.screen.NostrHomeRepliesFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.NostrVideoFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.NotificationViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size55Modifier
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user