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.StateFlow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
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
|
||||||
|
|
||||||
@@ -87,6 +88,10 @@ class BlossomServerListState(
|
|||||||
mergeServerList(blossoms)
|
mergeServerList(blossoms)
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(mergeServerList(flow.value))
|
emit(mergeServerList(flow.value))
|
||||||
|
}.onEach { servers ->
|
||||||
|
if (servers.none { it == settings.defaultFileServer }) {
|
||||||
|
settings.changeDefaultFileServer(servers.firstOrNull() ?: DEFAULT_MEDIA_SERVERS[0])
|
||||||
|
}
|
||||||
}.flowOn(Dispatchers.IO)
|
}.flowOn(Dispatchers.IO)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+1
-1
@@ -207,7 +207,7 @@ private fun ImageVideoPostChat(
|
|||||||
label = "",
|
label = "",
|
||||||
placeholder =
|
placeholder =
|
||||||
fileServers
|
fileServers
|
||||||
.firstOrNull { it == accountViewModel.account.settings.defaultFileServer }
|
.firstOrNull { it.baseUrl == accountViewModel.account.settings.defaultFileServer.baseUrl }
|
||||||
?.name
|
?.name
|
||||||
?: fileServers.firstOrNull()?.name
|
?: fileServers.firstOrNull()?.name
|
||||||
?: DEFAULT_MEDIA_SERVERS[0].name,
|
?: DEFAULT_MEDIA_SERVERS[0].name,
|
||||||
|
|||||||
Reference in New Issue
Block a user