From ddd1c19c47e7cd55acd40f4d42867d7f836c4ac4 Mon Sep 17 00:00:00 2001 From: davotoula Date: Tue, 14 Apr 2026 19:39:46 +0200 Subject: [PATCH] fix(hls): read user's configured Blossom servers from account The server dropdown on the HLS Upload screen was hardcoded to DEFAULT_MEDIA_SERVERS, so any Blossom server the user configured in Settings -> Media Servers did not appear. Wire it to account.blossomServers.hostNameFlow (same StateFlow the existing AllMediaBody settings screen consumes), which yields the signed BlossomServersEvent normalized into List and falls back to DEFAULT_MEDIA_SERVERS when the user has none configured. Initial selectedServer prefers account.settings.defaultFileServer when it is still in the list, otherwise the first available server. A collect job re-syncs the list if the user adds/removes servers while the screen is open. Co-Authored-By: Claude Opus 4.5 --- .../loggedIn/video/hls/NewHlsVideoScreen.kt | 6 ++--- .../video/hls/NewHlsVideoViewModel.kt | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoScreen.kt index ed10dc4f1..075a4fa78 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoScreen.kt @@ -76,8 +76,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.davotoula.lightcompressor.hls.HlsLadder import com.davotoula.lightcompressor.utils.CompressorUtils import com.vitorpamplona.amethyst.R -import com.vitorpamplona.amethyst.ui.actions.mediaServers.DEFAULT_MEDIA_SERVERS -import com.vitorpamplona.amethyst.ui.actions.mediaServers.ServerType import com.vitorpamplona.amethyst.ui.components.TextSpinner import com.vitorpamplona.amethyst.ui.components.TitleExplainer import com.vitorpamplona.amethyst.ui.navigation.navs.INav @@ -322,14 +320,14 @@ private fun FormFields(vm: NewHlsVideoViewModel) { Spacer(Modifier.height(16.dp)) - // Server picker + // Server picker — reads the user's configured Blossom servers from the account Text( text = stringResource(R.string.file_server), style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant, ) Spacer(Modifier.height(4.dp)) - val servers = remember { DEFAULT_MEDIA_SERVERS.filter { it.type != ServerType.NIP95 } } + val servers by vm.availableServers.collectAsState() val serverOptions = remember(servers) { servers.map { TitleExplainer(it.name, it.baseUrl) }.toImmutableList() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoViewModel.kt index d19795ac1..79f22db89 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/hls/NewHlsVideoViewModel.kt @@ -68,8 +68,12 @@ open class NewHlsVideoViewModel : ViewModel() { private val _state = MutableStateFlow(HlsPublishState.Idle) val state: StateFlow = _state.asStateFlow() + private val _availableServers = MutableStateFlow>(DEFAULT_MEDIA_SERVERS) + val availableServers: StateFlow> = _availableServers.asStateFlow() + private var orchestrator: HlsPublishOrchestrator? = null private var currentJob: Job? = null + private var serversJob: Job? = null fun load( account: Account, @@ -77,7 +81,27 @@ open class NewHlsVideoViewModel : ViewModel() { ) { this.account = account this.orchestrator = orchestrator - this.selectedServer = this.selectedServer ?: DEFAULT_MEDIA_SERVERS.first() + + val initialServers = account.blossomServers.hostNameFlow.value + _availableServers.value = initialServers + + if (selectedServer == null || initialServers.none { it == selectedServer }) { + selectedServer = account.settings.defaultFileServer + .takeIf { s -> initialServers.any { it == s } } + ?: initialServers.firstOrNull() + ?: DEFAULT_MEDIA_SERVERS.first() + } + + serversJob?.cancel() + serversJob = + viewModelScope.launch { + account.blossomServers.hostNameFlow.collect { servers -> + _availableServers.value = servers + if (selectedServer == null || servers.none { it == selectedServer }) { + selectedServer = servers.firstOrNull() ?: DEFAULT_MEDIA_SERVERS.first() + } + } + } } fun load(