mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 09:13:23 +00:00
Fixes crash on lazy flows when uploading images before the relay list is loaded.
This commit is contained in:
@@ -102,8 +102,6 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isLocalHost
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isOnion
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||
@@ -260,7 +258,7 @@ class Account(
|
||||
|
||||
val blossomServers = BlossomServerListState(signer, cache, scope, settings)
|
||||
val fileStorageServers = FileStorageServerListState(signer, cache, scope, settings)
|
||||
val serverLists = MergedServerListState(fileStorageServers.fileServers, blossomServers.fileServers, scope)
|
||||
val serverLists = MergedServerListState(fileStorageServers, blossomServers, scope)
|
||||
|
||||
// Relay settings
|
||||
val outboxRelays = AccountOutboxRelayState(nip65RelayList, privateStorageRelayList, localRelayList, scope)
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ class FileStorageServerListState(
|
||||
return event?.servers() ?: emptyList()
|
||||
}
|
||||
|
||||
val fileServers =
|
||||
val flow =
|
||||
getFileServersListFlow()
|
||||
.map { normalizeServers(it.note) }
|
||||
.onStart { emit(normalizeServers(getFileServersNote())) }
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class BlossomServerListState(
|
||||
return event?.servers() ?: emptyList()
|
||||
}
|
||||
|
||||
val fileServers =
|
||||
val flow =
|
||||
getBlossomServersListFlow()
|
||||
.map { normalizeServers(it.note) }
|
||||
.onStart { emit(normalizeServers(getBlossomServersNote())) }
|
||||
|
||||
+10
-10
@@ -20,7 +20,8 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.model.serverList
|
||||
|
||||
import android.R.attr.host
|
||||
import com.vitorpamplona.amethyst.model.nip96FileStorage.FileStorageServerListState
|
||||
import com.vitorpamplona.amethyst.model.nipB7Blossom.BlossomServerListState
|
||||
import com.vitorpamplona.amethyst.ui.actions.mediaServers.DEFAULT_MEDIA_SERVERS
|
||||
import com.vitorpamplona.amethyst.ui.actions.mediaServers.ServerName
|
||||
import com.vitorpamplona.amethyst.ui.actions.mediaServers.ServerType
|
||||
@@ -30,14 +31,13 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import org.czeal.rfc3986.URIReference
|
||||
|
||||
class MergedServerListState(
|
||||
val fileServers: StateFlow<List<String>>,
|
||||
val blossomServers: StateFlow<List<String>>,
|
||||
val fileServers: FileStorageServerListState,
|
||||
val blossomServers: BlossomServerListState,
|
||||
val scope: CoroutineScope,
|
||||
) {
|
||||
fun host(url: String): String =
|
||||
@@ -59,15 +59,15 @@ class MergedServerListState(
|
||||
return result + ServerName("NIP95", "", ServerType.NIP95)
|
||||
}
|
||||
|
||||
val liveServerList: StateFlow<List<ServerName>> by lazy {
|
||||
combine(fileServers, blossomServers) { nip96s, blossoms ->
|
||||
val liveServerList: StateFlow<List<ServerName>> =
|
||||
combine(fileServers.flow, blossomServers.flow) { nip96s, blossoms ->
|
||||
mergeServerList(nip96s, blossoms)
|
||||
}.onStart { emit(mergeServerList(fileServers.value, blossomServers.value)) }
|
||||
.flowOn(Dispatchers.Default)
|
||||
}.onStart {
|
||||
emit(mergeServerList(fileServers.flow.value, blossomServers.flow.value))
|
||||
}.flowOn(Dispatchers.Default)
|
||||
.stateIn(
|
||||
scope,
|
||||
SharingStarted.Eagerly,
|
||||
emptyList(),
|
||||
DEFAULT_MEDIA_SERVERS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -127,5 +127,5 @@ class BlossomServersViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun obtainFileServers(): List<String>? = account.blossomServers.fileServers.value
|
||||
private fun obtainFileServers(): List<String>? = account.blossomServers.flow.value
|
||||
}
|
||||
|
||||
+1
-1
@@ -122,5 +122,5 @@ class NIP96ServersViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun obtainFileServers(): List<String>? = account.fileStorageServers.fileServers.value
|
||||
private fun obtainFileServers(): List<String>? = account.fileStorageServers.flow.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user