Bookmarks: "this channel" button instead of the channel's "Add to bookmarks"

The bookmark editors (desktop dialog, Android screen) get TeamSpeak's
button beside the default channel, with its MAKE_CURRENT_CHANNEL_DEFAULT
icon: it takes the channel we are in, enabled while we are on the server
the form's address and port lead to (Sessions.connectedTo). The Android
channel sheet drops "Add to bookmarks"; the server sheet keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 21:03:04 +00:00
co-authored by Claude Opus 5.5
parent 173e710960
commit 3948db69bb
7 changed files with 86 additions and 14 deletions
@@ -347,10 +347,10 @@ class SessionController(private val context: Context) {
}
/** The channels of a server we are on at [host]:[port], to pick one to join. */
fun channelPathsAt(host: String, port: Int): List<String> =
_servers.value.firstOrNull {
it.isConnected && it.session.port() == port && it.session.address().equals(host.trim(), ignoreCase = true)
}?.session?.channelPaths().orEmpty()
fun channelPathsAt(host: String, port: Int): List<String> = sessions.connectedTo(host, port)?.channelPaths().orEmpty()
/** The channel we are in on the server at [host]:[port]; null when we are not on it. */
fun currentChannelAt(host: String, port: Int): String? = sessions.connectedTo(host, port)?.currentChannelPath()
fun removeBookmark(bookmark: Bookmark) {
val index = bookmarkStore.all().indexOf(bookmark)
@@ -15,6 +15,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuAnchorType
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -117,7 +118,10 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
val paths = remember(address) {
SessionController.parseAddress(address).let { (host, port) -> vm.channelPathsAt(host, port) }
}
ChannelField(channel, paths) { channel = it }
val current = remember(address) {
SessionController.parseAddress(address).let { (host, port) -> vm.currentChannelAt(host, port) }
}
ChannelField(channel, paths, current) { channel = it }
OutlinedTextField(channelPassword, { channelPassword = it }, Modifier.fillMaxWidth(),
label = { Text("Channel password") }, singleLine = true,
visualTransformation = PasswordVisualTransformation(),
@@ -141,10 +145,13 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
}
}
/** The channel to join, typed or picked among [paths] of the server when we are on it. */
/**
* The channel to join, typed or picked among [paths] of the server when we are on it,
* or taken from [current], the one we are in there.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ChannelField(channel: String, paths: List<String>, onChange: (String) -> Unit) {
private fun ChannelField(channel: String, paths: List<String>, current: String?, onChange: (String) -> Unit) {
var open by remember { mutableStateOf(false) }
// A channel already picked lists them all, for picking another.
val matches = if (channel in paths) paths else paths.filter { it.contains(channel.trim(), ignoreCase = true) }
@@ -154,7 +161,14 @@ private fun ChannelField(channel: String, paths: List<String>, onChange: (String
channel, { onChange(it); open = true }, singleLine = true,
label = { Text("Channel") },
placeholder = { Text("Default") },
trailingIcon = if (paths.isEmpty()) null else ({ ExposedDropdownMenuDefaults.TrailingIcon(expanded) }),
trailingIcon = {
Row(verticalAlignment = Alignment.CenterVertically) {
IconButton(onClick = { current?.let(onChange) }, enabled = current != null) {
PackIcon(listOf("MAKE_CURRENT_CHANNEL_DEFAULT", "CHANNEL_SWITCH"), "This channel")
}
if (paths.isNotEmpty()) ExposedDropdownMenuDefaults.TrailingIcon(expanded)
}
},
modifier = Modifier.fillMaxWidth().menuAnchor(ExposedDropdownMenuAnchorType.PrimaryEditable),
)
ExposedDropdownMenu(expanded, { open = false }) {
@@ -428,7 +428,6 @@ fun ServerScreen(
onDismiss = { channelSheet = null },
onJoin = { join(channel); channelSheet = null },
onSubscribe = { server.setSubscribed(id, it); channelSheet = null },
onBookmark = { channelSheet = null; bookmarkHere(id) },
onWhisper = if (state.whisperControls) ({ channelSheet = null; server.whisperToChannel(id) }) else null,
onAddToWhisperList = if (state.whisperControls) ({
channelSheet = null
@@ -145,7 +145,6 @@ fun ChannelSheet(
onDismiss: () -> Unit,
onJoin: () -> Unit,
onSubscribe: (Boolean) -> Unit,
onBookmark: () -> Unit,
/** Both null when whisper controls are hidden. */
onWhisper: (() -> Unit)?,
onAddToWhisperList: (() -> Unit)?,
@@ -171,7 +170,6 @@ fun ChannelSheet(
onWhisper?.let { Action("WHISPER", "Whisper", onClick = it) }
onAddToWhisperList?.let { Action("ON_WHISPERLIST", "Add to whisper list…", onClick = it) }
onFiles?.let { Action("FILETRANSFER", "Browse files", onClick = it) }
Action("BOOKMARK_ADD", "Add to bookmarks", onClick = onBookmark)
onCreateSub?.let { Action("CHANNEL_CREATE_SUB", "Create sub-channel", onClick = it) }
onEdit?.let { Action("CHANNEL_EDIT", "Edit channel", onClick = it) }
onDelete?.let { Action("CHANNEL_DELETE", "Delete channel", onClick = it) }