Slightly improving the threading for badges.
This commit is contained in:
@@ -43,6 +43,7 @@ import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun LoadDecryptedContent(
|
||||
@@ -116,10 +117,12 @@ fun LoadAddressableNote(
|
||||
|
||||
if (note == null) {
|
||||
LaunchedEffect(key1 = aTag) {
|
||||
accountViewModel.getOrCreateAddressableNote(aTag) { newNote ->
|
||||
if (newNote != note) {
|
||||
note = newNote
|
||||
val newNote =
|
||||
withContext(Dispatchers.IO) {
|
||||
accountViewModel.getOrCreateAddressableNote(aTag)
|
||||
}
|
||||
if (note != newNote) {
|
||||
note = newNote
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -946,7 +946,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
||||
viewModelScope.launch(Dispatchers.IO) { onResult(checkGetOrCreateAddressableNote(key)) }
|
||||
}
|
||||
|
||||
private suspend fun getOrCreateAddressableNote(key: ATag): AddressableNote? {
|
||||
suspend fun getOrCreateAddressableNote(key: ATag): AddressableNote? {
|
||||
return LocalCache.getOrCreateAddressableNote(key)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import androidx.compose.foundation.pager.PagerState
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.CutCornerShape
|
||||
import androidx.compose.foundation.text.ClickableText
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -163,7 +164,6 @@ import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.ZeroPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||
import com.vitorpamplona.quartz.encoders.ATag
|
||||
import com.vitorpamplona.quartz.events.AppDefinitionEvent
|
||||
import com.vitorpamplona.quartz.events.BadgeDefinitionEvent
|
||||
import com.vitorpamplona.quartz.events.BadgeProfilesEvent
|
||||
@@ -1289,14 +1289,8 @@ private fun DisplayBadges(
|
||||
}
|
||||
|
||||
LoadAddressableNote(
|
||||
aTag =
|
||||
ATag(
|
||||
BadgeProfilesEvent.KIND,
|
||||
baseUser.pubkeyHex,
|
||||
BadgeProfilesEvent.STANDARD_D_TAG,
|
||||
null,
|
||||
),
|
||||
accountViewModel,
|
||||
aTag = BadgeProfilesEvent.createAddressTag(baseUser.pubkeyHex),
|
||||
accountViewModel = accountViewModel,
|
||||
) { note ->
|
||||
if (note != null) {
|
||||
WatchAndRenderBadgeList(note, automaticallyShowProfilePicture, nav)
|
||||
@@ -1342,7 +1336,7 @@ private fun LoadAndRenderBadge(
|
||||
loadProfilePicture: Boolean,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
var baseNote by remember { mutableStateOf(LocalCache.getNoteIfExists(badgeAwardEventHex)) }
|
||||
var baseNote by remember(badgeAwardEventHex) { mutableStateOf(LocalCache.getNoteIfExists(badgeAwardEventHex)) }
|
||||
|
||||
LaunchedEffect(key1 = badgeAwardEventHex) {
|
||||
if (baseNote == null) {
|
||||
@@ -1440,7 +1434,7 @@ private fun WatchAndRenderBadgeImage(
|
||||
pictureModifier
|
||||
.width(size)
|
||||
.height(size)
|
||||
.clip(shape = CircleShape)
|
||||
.clip(shape = CutCornerShape(20))
|
||||
.background(bgColor)
|
||||
.run {
|
||||
if (onClick != null) {
|
||||
|
||||
Reference in New Issue
Block a user