Improves Relay Icon flow

This commit is contained in:
Vitor Pamplona
2025-07-02 14:16:26 -04:00
parent 8c11ae5c87
commit d0e66504e4
3 changed files with 72 additions and 74 deletions
@@ -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,
@@ -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<Nip11RelayInformation?> {
@Suppress("ProduceStateDoesNotAssignValue")
val relayInfo =
produceStateIfNotNull(
Nip11CachedRetriever.getFromCache(relay),
relay,
) {
accountViewModel.retrieveRelayDocument(
relay = relay,
onInfo = { value = it },
onError = { url, errorCode, exceptionMessage -> },
)
}
return relayInfo
}
): State<Nip11RelayInformation> =
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(
@@ -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<Int>?,
val supported_nip_extensions: List<String>?,
val software: String?,
val version: String?,
val limitation: RelayInformationLimitation?,
val relay_countries: List<String>?,
val language_tags: List<String>?,
val tags: List<String>?,
val posting_policy: String?,
val payments_url: String?,
val retention: List<RelayInformationRetentionData>?,
val fees: RelayInformationFees?,
val nip50: List<String>?,
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<Int>? = null,
val supported_nip_extensions: List<String>? = null,
val software: String? = null,
val version: String? = null,
val limitation: RelayInformationLimitation? = null,
val relay_countries: List<String>? = null,
val language_tags: List<String>? = null,
val tags: List<String>? = null,
val posting_policy: String? = null,
val payments_url: String? = null,
val retention: List<RelayInformationRetentionData>? = null,
val fees: RelayInformationFees? = null,
val nip50: List<String>? = 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<Int>?,
val amount: Int? = null,
val unit: String? = null,
val period: Int? = null,
val kinds: List<Int>? = null,
)
class RelayInformationFees(
val admission: List<RelayInformationFee>?,
val subscription: List<RelayInformationFee>?,
val publication: List<RelayInformationFee>?,
val admission: List<RelayInformationFee>? = null,
val subscription: List<RelayInformationFee>? = null,
val publication: List<RelayInformationFee>? = 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<Int>?,
val tiem: Int?,
val count: Int?,
val kinds: ArrayList<Int>? = null,
val tiem: Int? = null,
val count: Int? = null,
)