From 63e036a9bbae5de18002989a65f530cd2a72943c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Aug 2024 12:32:44 -0400 Subject: [PATCH] Minimizes relay updates when rotating status events for each user. --- .../ui/note/NIP05VerificationDisplay.kt | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt index 3e6e49e0e..b94ab27a8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt @@ -71,6 +71,7 @@ import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer import com.vitorpamplona.amethyst.ui.theme.lessImportantLink import com.vitorpamplona.amethyst.ui.theme.nip05 import com.vitorpamplona.amethyst.ui.theme.placeholderText +import com.vitorpamplona.quartz.encoders.ATag import com.vitorpamplona.quartz.events.AddressableEvent import com.vitorpamplona.quartz.events.UserMetadata import com.vitorpamplona.quartz.utils.TimeUtils @@ -168,7 +169,7 @@ private fun VerifyAndDisplayNIP05OrStatusLine( if (nip05Verified.value != true) { DisplayNIP05(nip05, nip05Verified, accountViewModel) } else if (!statuses.isEmpty()) { - RotateStatuses(statuses, accountViewModel, nav) + ObserveRotateStatuses(statuses, accountViewModel, nav) } else { DisplayNIP05(nip05, nip05Verified, accountViewModel) } @@ -183,6 +184,29 @@ private fun VerifyAndDisplayNIP05OrStatusLine( } } +@Composable +fun ObserveRotateStatuses( + statuses: ImmutableList, + accountViewModel: AccountViewModel, + nav: (String) -> Unit, +) { + ObserveAllStatusesToAvoidSwitchigAllTheTime(statuses) + + RotateStatuses( + statuses, + accountViewModel, + nav, + ) +} + +@Composable +fun ObserveAllStatusesToAvoidSwitchigAllTheTime(statuses: ImmutableList) { + statuses + .map { + it.live().metadata.observeAsState() + } +} + @Composable fun RotateStatuses( statuses: ImmutableList, @@ -221,14 +245,29 @@ fun DisplayStatus( nav: (String) -> Unit, ) { val noteState by addressableNote.live().metadata.observeAsState() + val noteEvent = noteState?.note?.event ?: return - val content = remember(noteState) { addressableNote.event?.content() ?: "" } - val type = remember(noteState) { (addressableNote.event as? AddressableEvent)?.dTag() ?: "" } - val url = remember(noteState) { addressableNote.event?.firstTaggedUrl()?.ifBlank { null } } - val nostrATag = remember(noteState) { addressableNote.event?.firstTaggedAddress() } - val nostrHexID = - remember(noteState) { addressableNote.event?.firstTaggedEvent()?.ifBlank { null } } + DisplayStatusInner( + noteEvent.content(), + (noteEvent as? AddressableEvent)?.dTag() ?: "", + noteEvent.firstTaggedUrl()?.ifBlank { null }, + noteEvent.firstTaggedAddress(), + noteEvent.firstTaggedEvent()?.ifBlank { null }, + accountViewModel, + nav, + ) +} +@Composable +fun DisplayStatusInner( + content: String, + type: String, + url: String?, + nostrATag: ATag?, + nostrHexID: String?, + accountViewModel: AccountViewModel, + nav: (String) -> Unit, +) { when (type) { "music" -> Icon(