mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-09 23:12:32 +02:00
Minimizes relay updates when rotating status events for each user.
This commit is contained in:
@@ -71,6 +71,7 @@ import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.lessImportantLink
|
import com.vitorpamplona.amethyst.ui.theme.lessImportantLink
|
||||||
import com.vitorpamplona.amethyst.ui.theme.nip05
|
import com.vitorpamplona.amethyst.ui.theme.nip05
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.events.AddressableEvent
|
import com.vitorpamplona.quartz.events.AddressableEvent
|
||||||
import com.vitorpamplona.quartz.events.UserMetadata
|
import com.vitorpamplona.quartz.events.UserMetadata
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
@@ -168,7 +169,7 @@ private fun VerifyAndDisplayNIP05OrStatusLine(
|
|||||||
if (nip05Verified.value != true) {
|
if (nip05Verified.value != true) {
|
||||||
DisplayNIP05(nip05, nip05Verified, accountViewModel)
|
DisplayNIP05(nip05, nip05Verified, accountViewModel)
|
||||||
} else if (!statuses.isEmpty()) {
|
} else if (!statuses.isEmpty()) {
|
||||||
RotateStatuses(statuses, accountViewModel, nav)
|
ObserveRotateStatuses(statuses, accountViewModel, nav)
|
||||||
} else {
|
} else {
|
||||||
DisplayNIP05(nip05, nip05Verified, accountViewModel)
|
DisplayNIP05(nip05, nip05Verified, accountViewModel)
|
||||||
}
|
}
|
||||||
@@ -183,6 +184,29 @@ private fun VerifyAndDisplayNIP05OrStatusLine(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ObserveRotateStatuses(
|
||||||
|
statuses: ImmutableList<AddressableNote>,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
ObserveAllStatusesToAvoidSwitchigAllTheTime(statuses)
|
||||||
|
|
||||||
|
RotateStatuses(
|
||||||
|
statuses,
|
||||||
|
accountViewModel,
|
||||||
|
nav,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ObserveAllStatusesToAvoidSwitchigAllTheTime(statuses: ImmutableList<AddressableNote>) {
|
||||||
|
statuses
|
||||||
|
.map {
|
||||||
|
it.live().metadata.observeAsState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RotateStatuses(
|
fun RotateStatuses(
|
||||||
statuses: ImmutableList<AddressableNote>,
|
statuses: ImmutableList<AddressableNote>,
|
||||||
@@ -221,14 +245,29 @@ fun DisplayStatus(
|
|||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val noteState by addressableNote.live().metadata.observeAsState()
|
val noteState by addressableNote.live().metadata.observeAsState()
|
||||||
|
val noteEvent = noteState?.note?.event ?: return
|
||||||
|
|
||||||
val content = remember(noteState) { addressableNote.event?.content() ?: "" }
|
DisplayStatusInner(
|
||||||
val type = remember(noteState) { (addressableNote.event as? AddressableEvent)?.dTag() ?: "" }
|
noteEvent.content(),
|
||||||
val url = remember(noteState) { addressableNote.event?.firstTaggedUrl()?.ifBlank { null } }
|
(noteEvent as? AddressableEvent)?.dTag() ?: "",
|
||||||
val nostrATag = remember(noteState) { addressableNote.event?.firstTaggedAddress() }
|
noteEvent.firstTaggedUrl()?.ifBlank { null },
|
||||||
val nostrHexID =
|
noteEvent.firstTaggedAddress(),
|
||||||
remember(noteState) { addressableNote.event?.firstTaggedEvent()?.ifBlank { null } }
|
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) {
|
when (type) {
|
||||||
"music" ->
|
"music" ->
|
||||||
Icon(
|
Icon(
|
||||||
|
Reference in New Issue
Block a user