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<ServerName> 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 <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-04-14 19:39:46 +02:00
parent 9e49353acb
commit ddd1c19c47
2 changed files with 27 additions and 5 deletions
@@ -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()
@@ -68,8 +68,12 @@ open class NewHlsVideoViewModel : ViewModel() {
private val _state = MutableStateFlow<HlsPublishState>(HlsPublishState.Idle)
val state: StateFlow<HlsPublishState> = _state.asStateFlow()
private val _availableServers = MutableStateFlow<List<ServerName>>(DEFAULT_MEDIA_SERVERS)
val availableServers: StateFlow<List<ServerName>> = _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(