Dynamically adjust the preferred server to the first one when the list changes and the current default is not in the list of servers.
This commit is contained in:
+5
@@ -38,6 +38,7 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
|
||||
@@ -87,6 +88,10 @@ class BlossomServerListState(
|
||||
mergeServerList(blossoms)
|
||||
}.onStart {
|
||||
emit(mergeServerList(flow.value))
|
||||
}.onEach { servers ->
|
||||
if (servers.none { it == settings.defaultFileServer }) {
|
||||
settings.changeDefaultFileServer(servers.firstOrNull() ?: DEFAULT_MEDIA_SERVERS[0])
|
||||
}
|
||||
}.flowOn(Dispatchers.IO)
|
||||
.stateIn(
|
||||
scope,
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ private fun ImageVideoPostChat(
|
||||
label = "",
|
||||
placeholder =
|
||||
fileServers
|
||||
.firstOrNull { it == accountViewModel.account.settings.defaultFileServer }
|
||||
.firstOrNull { it.baseUrl == accountViewModel.account.settings.defaultFileServer.baseUrl }
|
||||
?.name
|
||||
?: fileServers.firstOrNull()?.name
|
||||
?: DEFAULT_MEDIA_SERVERS[0].name,
|
||||
|
||||
Reference in New Issue
Block a user