Improves caching on the allRelays call on the Nostr Client
This commit is contained in:
+1
-3
@@ -47,11 +47,9 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.google.common.collect.Multimaps.index
|
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
import com.vitorpamplona.amethyst.ui.components.SetDialogToEdgeToEdge
|
import com.vitorpamplona.amethyst.ui.components.SetDialogToEdgeToEdge
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.EmptyNav.nav
|
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
import com.vitorpamplona.amethyst.ui.navigation.INav
|
||||||
import com.vitorpamplona.amethyst.ui.note.buttons.CloseButton
|
import com.vitorpamplona.amethyst.ui.note.buttons.CloseButton
|
||||||
import com.vitorpamplona.amethyst.ui.note.buttons.SaveButton
|
import com.vitorpamplona.amethyst.ui.note.buttons.SaveButton
|
||||||
@@ -89,7 +87,7 @@ fun RelaySelectionDialog(
|
|||||||
) {
|
) {
|
||||||
var relays by remember {
|
var relays by remember {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
accountViewModel.account.client.connectedRelayList().map {
|
accountViewModel.account.client.allAvailableRelays().map {
|
||||||
RelayList(
|
RelayList(
|
||||||
relay = it,
|
relay = it,
|
||||||
isSelected = preSelectedList.any { relayUrl -> it == relayUrl },
|
isSelected = preSelectedList.any { relayUrl -> it == relayUrl },
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.forEach
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
@@ -89,7 +88,7 @@ class NostrClient(
|
|||||||
eventOutbox.forEachUnsentEvent(relay, liveRelay::send)
|
eventOutbox.forEachUnsentEvent(relay, liveRelay::send)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun connectedRelayList() = relayPool.getAll()
|
fun allAvailableRelays() = relayPool.getAll()
|
||||||
|
|
||||||
// Reconnects all relays that may have disconnected
|
// Reconnects all relays that may have disconnected
|
||||||
fun connect() = relayPool.connect()
|
fun connect() = relayPool.connect()
|
||||||
@@ -239,7 +238,5 @@ class NostrClient(
|
|||||||
|
|
||||||
fun getSubscriptionFiltersOrNull(subId: String): List<RelayBasedFilter>? = activeSubscriptions.getSubscriptionFiltersOrNull(subId)
|
fun getSubscriptionFiltersOrNull(subId: String): List<RelayBasedFilter>? = activeSubscriptions.getSubscriptionFiltersOrNull(subId)
|
||||||
|
|
||||||
fun connectedRelays() = relayPool.connectedRelays()
|
|
||||||
|
|
||||||
fun relayStatusFlow() = relayPool.statusFlow
|
fun relayStatusFlow() = relayPool.statusFlow
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ class RelayPool(
|
|||||||
|
|
||||||
fun getRelay(url: NormalizedRelayUrl): IRelayClient? = relays.get(url)
|
fun getRelay(url: NormalizedRelayUrl): IRelayClient? = relays.get(url)
|
||||||
|
|
||||||
fun getAll() = relays.keys()
|
fun getAll() = statusFlow.value.connected
|
||||||
|
|
||||||
fun getAllNeedsToReconnect() = relays.filter { url, relay -> relay.needsToReconnect() }
|
fun getAllNeedsToReconnect() = relays.filter { url, relay -> relay.needsToReconnect() }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user