From b1a355691a3180c9ea120b806144d879379ca22c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 1 Mar 2024 13:41:43 -0500 Subject: [PATCH] Fixes another caching issue when multiple posts include the same poll. --- .../amethyst/ui/note/PollNoteViewModel.kt | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt index 0c03ebd7a..5f4949bc8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt @@ -76,29 +76,31 @@ class PollNoteViewModel : ViewModel() { acc: Account, note: Note?, ) { - account = acc - pollNote = note - pollEvent = pollNote?.event as PollNoteEvent - pollOptions = pollEvent?.pollOptions() - valueMaximum = pollEvent?.getTagLong(VALUE_MAXIMUM) - valueMinimum = pollEvent?.getTagLong(VALUE_MINIMUM) - valueMinimumBD = valueMinimum?.let { BigDecimal(it) } - valueMaximumBD = valueMaximum?.let { BigDecimal(it) } - consensusThreshold = - pollEvent?.getTagLong(CONSENSUS_THRESHOLD)?.toFloat()?.div(100)?.toBigDecimal() - closedAt = pollEvent?.getTagLong(CLOSED_AT) + if (acc != account || pollNote != note) { + account = acc + pollNote = note + pollEvent = pollNote?.event as PollNoteEvent + pollOptions = pollEvent?.pollOptions() + valueMaximum = pollEvent?.getTagLong(VALUE_MAXIMUM) + valueMinimum = pollEvent?.getTagLong(VALUE_MINIMUM) + valueMinimumBD = valueMinimum?.let { BigDecimal(it) } + valueMaximumBD = valueMaximum?.let { BigDecimal(it) } + consensusThreshold = + pollEvent?.getTagLong(CONSENSUS_THRESHOLD)?.toFloat()?.div(100)?.toBigDecimal() + closedAt = pollEvent?.getTagLong(CLOSED_AT) - totalZapped = BigDecimal.ZERO - wasZappedByLoggedInAccount = false + totalZapped = BigDecimal.ZERO + wasZappedByLoggedInAccount = false - canZap.value = checkIfCanZap() + canZap.value = checkIfCanZap() - tallies = pollOptions?.keys?.map { option -> - PollOption( - option, - pollOptions?.get(option) ?: "", - ) - } ?: emptyList() + tallies = pollOptions?.keys?.map { option -> + PollOption( + option, + pollOptions?.get(option) ?: "", + ) + } ?: emptyList() + } } fun refreshTallies() {