From 31959721b1cb5935f6633348094710432a01f46c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Jun 2023 21:27:57 -0400 Subject: [PATCH] Moves reward calculations to the IO thread --- .../vitorpamplona/amethyst/ui/note/NoteCompose.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 2dcbfd00b..cb9e70816 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 @@ -1712,11 +1712,17 @@ private fun RenderPledgeAmount( } LaunchedEffect(key1 = repliesState) { - withContext(Dispatchers.IO) { + launch(Dispatchers.IO) { repliesState?.note?.pledgedAmountByOthers()?.let { - rewardAmount = baseReward.add(it) + val newRewardAmount = baseReward.add(it) + if (newRewardAmount != rewardAmount) { + rewardAmount = newRewardAmount + } + } + val newHasPledge = repliesState?.note?.hasPledgeBy(accountViewModel.userProfile()) == true + if (hasPledge != newHasPledge) { + hasPledge = newHasPledge } - hasPledge = repliesState?.note?.hasPledgeBy(accountViewModel.userProfile()) == true } }