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(