diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt index 3379d9025..48a8ee08e 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt @@ -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 } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 41cf6886f..cd31b9071 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -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) } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index 142ac1254..00f2f86df 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -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) { diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/BadgeProfilesEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/BadgeProfilesEvent.kt index 0c235d6b2..f38ab0e8a 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/BadgeProfilesEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/BadgeProfilesEvent.kt @@ -33,21 +33,17 @@ class BadgeProfilesEvent( content: String, sig: HexKey, ) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) { - fun badgeAwardEvents() = tags.filter { it.firstOrNull() == "e" }.mapNotNull { it.getOrNull(1) } + fun badgeAwardEvents() = taggedEvents() - fun badgeAwardDefinitions() = - tags - .filter { it.firstOrNull() == "a" } - .mapNotNull { - val aTagValue = it.getOrNull(1) - val relay = it.getOrNull(2) - - if (aTagValue != null) ATag.parse(aTagValue, relay) else null - } + fun badgeAwardDefinitions() = taggedAddresses() companion object { const val KIND = 30008 - const val STANDARD_D_TAG = "profile_badges" - const val ALT = "List of accepted badges by the author" + private const val STANDARD_D_TAG = "profile_badges" + private const val ALT = "List of accepted badges by the author" + + fun createAddressTag(pubKey: HexKey): ATag { + return ATag(KIND, pubKey, STANDARD_D_TAG, null) + } } }