From d0e66504e459cc1bdd3db6a4b4e67ba797e4a42f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 2 Jul 2025 14:16:26 -0400 Subject: [PATCH] Improves Relay Icon flow --- .../amethyst/ui/note/RelayListRow.kt | 25 +++--- .../header/ShortEphemeralChatChannelHeader.kt | 35 ++++---- .../nip11RelayInfo/Nip11RelayInformation.kt | 86 +++++++++---------- 3 files changed, 72 insertions(+), 74 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt index 5317a458e..5e5eb7d38 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt @@ -127,15 +127,13 @@ fun RenderRelay( var openRelayDialog by remember { mutableStateOf(false) } if (openRelayDialog) { - relayInfo?.let { - RelayInformationDialog( - onClose = { openRelayDialog = false }, - relayInfo = it, - relay = relay, - accountViewModel = accountViewModel, - nav = nav, - ) - } + RelayInformationDialog( + onClose = { openRelayDialog = false }, + relayInfo = relayInfo, + relay = relay, + accountViewModel = accountViewModel, + nav = nav, + ) } val clipboardManager = LocalClipboardManager.current @@ -150,11 +148,10 @@ fun RenderRelay( clipboardManager.setText(AnnotatedString(relay.url)) }, onClick = { + openRelayDialog = true accountViewModel.retrieveRelayDocument( relay, - onInfo = { - openRelayDialog = true - }, + onInfo = { }, onError = { url, errorCode, exceptionMessage -> accountViewModel.toastManager.toast( R.string.unable_to_download_relay_document, @@ -185,8 +182,8 @@ fun RenderRelay( contentAlignment = Alignment.Center, ) { RenderRelayIcon( - displayUrl = relay.displayUrl(), - iconUrl = relayInfo?.icon, + displayUrl = relayInfo.id ?: relay.url, + iconUrl = relayInfo.icon, loadProfilePicture = accountViewModel.settings.showProfilePictures.value, pingInMs = 0, loadRobohash = accountViewModel.settings.featureSet != FeatureSetType.PERFORMANCE, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/header/ShortEphemeralChatChannelHeader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/header/ShortEphemeralChatChannelHeader.kt index 6550a5f6d..795636635 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/header/ShortEphemeralChatChannelHeader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/header/ShortEphemeralChatChannelHeader.kt @@ -20,6 +20,7 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.ephemChat.header +import android.util.Log import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -29,12 +30,14 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.getValue +import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import com.fasterxml.jackson.databind.util.ClassUtil.exceptionMessage import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.EphemeralChatChannel import com.vitorpamplona.amethyst.model.FeatureSetType @@ -43,7 +46,6 @@ import com.vitorpamplona.amethyst.service.relayClient.reqCommand.channel.observe import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserIsFollowingChannel import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage import com.vitorpamplona.amethyst.ui.navigation.INav -import com.vitorpamplona.amethyst.ui.note.produceStateIfNotNull import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.ephemChat.header.actions.JoinChatButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.ephemChat.header.actions.LeaveChatButton @@ -57,22 +59,21 @@ import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation fun loadRelayInfo( relay: NormalizedRelayUrl, accountViewModel: AccountViewModel, -): State { - @Suppress("ProduceStateDoesNotAssignValue") - val relayInfo = - produceStateIfNotNull( - Nip11CachedRetriever.getFromCache(relay), - relay, - ) { - accountViewModel.retrieveRelayDocument( - relay = relay, - onInfo = { value = it }, - onError = { url, errorCode, exceptionMessage -> }, - ) - } - - return relayInfo -} +): State = + produceState( + Nip11CachedRetriever.getFromCache(relay), + relay, + ) { + accountViewModel.retrieveRelayDocument( + relay = relay, + onInfo = { + value = it + }, + onError = { url, errorCode, exceptionMessage -> + Log.e("RelayInfo", "Error loading relay info for ${url.url}: $errorCode - $exceptionMessage") + }, + ) + } @Composable fun ShortEphemeralChatChannelHeader( diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip11RelayInfo/Nip11RelayInformation.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip11RelayInfo/Nip11RelayInformation.kt index 4aded0889..9506c1628 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip11RelayInfo/Nip11RelayInformation.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip11RelayInfo/Nip11RelayInformation.kt @@ -26,25 +26,25 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper @Stable class Nip11RelayInformation( - val id: String?, - val name: String?, - val description: String?, - val icon: String?, - val pubkey: String?, - val contact: String?, - val supported_nips: List?, - val supported_nip_extensions: List?, - val software: String?, - val version: String?, - val limitation: RelayInformationLimitation?, - val relay_countries: List?, - val language_tags: List?, - val tags: List?, - val posting_policy: String?, - val payments_url: String?, - val retention: List?, - val fees: RelayInformationFees?, - val nip50: List?, + val id: String? = null, + val name: String? = null, + val description: String? = null, + val icon: String? = null, + val pubkey: String? = null, + val contact: String? = null, + val supported_nips: List? = null, + val supported_nip_extensions: List? = null, + val software: String? = null, + val version: String? = null, + val limitation: RelayInformationLimitation? = null, + val relay_countries: List? = null, + val language_tags: List? = null, + val tags: List? = null, + val posting_policy: String? = null, + val payments_url: String? = null, + val retention: List? = null, + val fees: RelayInformationFees? = null, + val nip50: List? = null, ) { companion object { val mapper = @@ -56,37 +56,37 @@ class Nip11RelayInformation( @Stable class RelayInformationFee( - val amount: Int?, - val unit: String?, - val period: Int?, - val kinds: List?, + val amount: Int? = null, + val unit: String? = null, + val period: Int? = null, + val kinds: List? = null, ) class RelayInformationFees( - val admission: List?, - val subscription: List?, - val publication: List?, + val admission: List? = null, + val subscription: List? = null, + val publication: List? = null, ) class RelayInformationLimitation( - val max_message_length: Int?, - val max_subscriptions: Int?, - val max_filters: Int?, - val max_limit: Int?, - val max_subid_length: Int?, - val min_prefix: Int?, - val max_event_tags: Int?, - val max_content_length: Int?, - val min_pow_difficulty: Int?, - val auth_required: Boolean?, - val payment_required: Boolean?, - val restricted_writes: Boolean?, - val created_at_lower_limit: Int?, - val created_at_upper_limit: Int?, + val max_message_length: Int? = null, + val max_subscriptions: Int? = null, + val max_filters: Int? = null, + val max_limit: Int? = null, + val max_subid_length: Int? = null, + val min_prefix: Int? = null, + val max_event_tags: Int? = null, + val max_content_length: Int? = null, + val min_pow_difficulty: Int? = null, + val auth_required: Boolean? = null, + val payment_required: Boolean? = null, + val restricted_writes: Boolean? = null, + val created_at_lower_limit: Int? = null, + val created_at_upper_limit: Int? = null, ) class RelayInformationRetentionData( - val kinds: ArrayList?, - val tiem: Int?, - val count: Int?, + val kinds: ArrayList? = null, + val tiem: Int? = null, + val count: Int? = null, )