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:
Vitor Pamplona
2026-03-28 20:21:57 -04:00
parent 589bb041b2
commit 4b5405c6b7
2 changed files with 6 additions and 1 deletions
@@ -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,
@@ -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,