Select several clients in the tree to move or kick them together

Desktop: Ctrl/Shift in the tree (ClientSelectionModel keeps a selection to
one row of any kind or several clients; a Shift range keeps its clients),
drag them onto a channel, or right-click for Kick Clients from Channel /
Server and Move Clients to own Channel. The selection survives rebuilds.
Android: long-press a client, tap more; a bar offers Move to…, Move to my
channel and both kicks (as far as we may), Back clears it.

Core sends one piped clientmove / clientkick. The server refuses the whole
pipe when one row fails ("already member of channel"), so it leaves out
clients already in the target, and for a channel kick those already in
the default channel, which the model now tracks (channel_flag_default).
Verified on a local 3.13.7 server with both frontends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 00:50:32 +00:00
co-authored by Claude Opus 5.5
parent 96e926168c
commit c41b86f704
12 changed files with 371 additions and 92 deletions
@@ -191,8 +191,11 @@ class ServerController internal constructor(
val canMoveClients: Boolean get() = session.canMoveClients()
fun moveClient(clientId: Int, channelId: Int) {
if (session.isConnected) conn.moveClient(clientId, channelId, null)
/** The channel kicked clients go back to; 0 until the server named it. */
val defaultChannelId: Int get() = conn.model.defaultChannelId()
fun moveClients(clientIds: Collection<Int>, channelId: Int) {
if (session.isConnected) conn.moveClients(clientIds, channelId)
}
fun poke(clientId: Int, message: String) {
@@ -295,12 +298,12 @@ class ServerController internal constructor(
/** The longest ban we may hand out in seconds; 0 or -1 for no limit. */
val maxBanSeconds: Long get() = conn.model.maxBanSeconds()
fun kickFromChannel(clientId: Int, reason: String) {
if (session.isConnected) conn.kickFromChannel(clientId, reason)
fun kickFromChannel(clientIds: Collection<Int>, reason: String) {
if (session.isConnected) conn.kickFromChannel(clientIds, reason)
}
fun kickFromServer(clientId: Int, reason: String) {
if (session.isConnected) conn.kickFromServer(clientId, reason)
fun kickFromServer(clientIds: Collection<Int>, reason: String) {
if (session.isConnected) conn.kickFromServer(clientIds, reason)
}
/** Bans a client for [seconds], or for good with 0. */
@@ -153,6 +153,10 @@ fun ChannelTree(
listState: LazyListState = rememberLazyListState(),
/** Brings our own client into view; its row may sit in folded channels. */
onShowSelf: () -> Unit = {},
/** Clients picked to be moved or kicked together. */
selected: Set<Int> = emptySet(),
/** Picks a client into [selected]; null when there is nothing to do with several. */
onClientLongPress: ((ClientItem) -> Unit)? = null,
) {
val rows = remember(tree, collapsed, currentChannel) { flatten(tree, collapsed, currentChannel) }
var flashing by remember { mutableStateOf<TreeRef?>(null) }
@@ -201,16 +205,17 @@ fun ChannelTree(
}
items(rows, key = { it.key }) { row ->
val background = rowBackground(
when (row.ref) {
flashing -> FLASH
foundCurrent -> findCurrentColor()
in found -> findMatchColor()
when {
row.ref == flashing -> FLASH
!row.ref.channel && row.ref.id in selected -> MaterialTheme.colorScheme.secondaryContainer
row.ref == foundCurrent -> findCurrentColor()
row.ref in found -> findMatchColor()
else -> Color.Transparent
},
)
when (row) {
is TreeRow.Channel -> ChannelRow(row, background, onToggle, onChannel, onChannelDoubleTap)
is TreeRow.Client -> ClientRow(row, tree.countryFlags, background, onClient)
is TreeRow.Client -> ClientRow(row, tree.countryFlags, background, onClient, onClientLongPress)
}
}
}
@@ -239,6 +244,7 @@ private fun RowLayout(
/** The colour under [background], which a flash or find match goes over. */
tint: Color = Color.Transparent,
onDoubleClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
content: @Composable RowScope.() -> Unit,
) {
Row(
@@ -247,7 +253,7 @@ private fun RowLayout(
.background(tint)
.background(background)
.height(ROW)
.then(if (onClick != null) Modifier.combinedClickable(onDoubleClick = onDoubleClick, onClick = onClick) else Modifier)
.then(if (onClick != null) Modifier.combinedClickable(onDoubleClick = onDoubleClick, onLongClick = onLongClick, onClick = onClick) else Modifier)
.padding(start = 4.dp + INDENT * depth, end = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp),
@@ -315,9 +321,16 @@ private fun SpacerLabel(align: Char, caption: String, modifier: Modifier) {
}
@Composable
private fun ClientRow(row: TreeRow.Client, countryFlags: Boolean, background: Color, onClient: (ClientItem) -> Unit) {
private fun ClientRow(
row: TreeRow.Client,
countryFlags: Boolean,
background: Color,
onClient: (ClientItem) -> Unit,
onLongPress: ((ClientItem) -> Unit)?,
) {
val client = row.client
RowLayout(row.depth, onClick = { onClient(client) }, background = background, tint = Color(client.background)) {
RowLayout(row.depth, onClick = { onClient(client) }, background = background, tint = Color(client.background),
onLongClick = onLongPress?.let { { it(client) } }) {
Spacer(Modifier.width(ICON + 4.dp))
StatusIcon(client.status)
Row(Modifier.weight(1f), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
@@ -211,7 +211,7 @@ fun ClientModeration(server: ServerController, client: ClientItem, onDone: () ->
onDismiss = { kick = null },
) { reason ->
kick = null
if (fromServer) server.kickFromServer(client.id, reason) else server.kickFromChannel(client.id, reason)
if (fromServer) server.kickFromServer(listOf(client.id), reason) else server.kickFromChannel(listOf(client.id), reason)
onDone()
}
}
@@ -22,6 +22,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
@@ -161,8 +162,23 @@ fun ServerScreen(
/** What is being added to a whisper list, while the list is picked: its name and how to add it. */
var toWhisperList by remember { mutableStateOf<Pair<String, (WhisperList) -> Unit>?>(null) }
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
/** The client to move, while a channel for them is being picked. */
var moving by remember { mutableStateOf<Int?>(null) }
/** The clients to move, while a channel for them is being picked. */
var moving by remember { mutableStateOf<Set<Int>?>(null) }
/** Clients picked by a long press, to be moved or kicked together; those who left fall out. */
var picked by remember { mutableStateOf(emptySet<Int>()) }
val selection = remember(picked, tree) { picked.filterTo(LinkedHashSet()) { tree.client(it) != null } }
/** Whether the selection is being kicked: from the server, or from their channels. */
var kickingSelection by remember { mutableStateOf<Boolean?>(null) }
/** Whom of the selection a kick goes to: never us, and from a channel, nobody already in the default one. */
val kickable = { fromServer: Boolean ->
val inDefault = if (fromServer) emptySet() else tree.channel(server.defaultChannelId)?.clients.orEmpty().map { it.id }.toSet()
selection - state.selfClientId - inDefault
}
val moveTo = { channelId: Int, clients: Set<Int> ->
server.moveClients(clients, channelId)
moving = null
picked = emptySet()
}
val infoUpdates by server.infoUpdates.collectAsStateWithLifecycle()
val chatRequest by server.chatRequest.collectAsStateWithLifecycle()
@@ -261,6 +277,7 @@ fun ServerScreen(
BackHandler(showChat) { showChat = false }
BackHandler(moving != null && !showChat) { moving = null }
BackHandler(moving == null && selection.isNotEmpty() && !showChat) { picked = emptySet() }
BackHandler(find.open) { find.open = false }
Scaffold(
@@ -304,13 +321,24 @@ fun ServerScreen(
) { padding ->
Column(Modifier.padding(padding).consumeWindowInsets(padding).imePadding()) {
if (!showChat) {
moving?.let { id ->
val client = tree.client(id)
if (client == null) {
LaunchedEffect(id) { moving = null }
val movingNow = moving
if (movingNow != null) {
val clients = movingNow.mapNotNull { tree.client(it) }
if (clients.isEmpty()) {
LaunchedEffect(movingNow) { moving = null }
} else {
MovePrompt(client.name) { moving = null }
MovePrompt(clients.singleOrNull()?.name ?: "${clients.size} clients") { moving = null }
}
} else if (selection.isNotEmpty()) {
val outside = tree.channel(state.channelId)?.clients.orEmpty().map { it.id }.let { selection - it.toSet() }
SelectionBar(
count = selection.size,
onMove = if (server.canMoveClients) ({ moving = selection }) else null,
onMoveHere = if (server.canMoveClients && outside.isNotEmpty()) ({ moveTo(state.channelId, outside) }) else null,
onKickChannel = if (server.canKickFromChannel && kickable(false).isNotEmpty()) ({ kickingSelection = false }) else null,
onKickServer = if (server.canKickFromServer && kickable(true).isNotEmpty()) ({ kickingSelection = true }) else null,
onClear = { picked = emptySet() },
)
}
ChannelTree(
serverName = state.title,
@@ -323,22 +351,28 @@ fun ServerScreen(
else filterCollapsed += it.id
},
onChannel = { channel ->
val client = moving
val clients = moving
when {
channel.spacer != null -> {}
client != null -> { server.moveClient(client, channel.id); moving = null }
clients != null -> moveTo(channel.id, clients)
else -> channelSheet = channel.id
}
},
onChannelDoubleTap = { channel ->
val client = moving
val clients = moving
when {
client != null -> { server.moveClient(client, channel.id); moving = null }
clients != null -> moveTo(channel.id, clients)
channel.id == state.channelId -> {}
else -> join(channel)
}
},
onClient = { clientSheet = it.id; clientSheetFromTree = true },
onClient = {
when {
selection.isEmpty() -> { clientSheet = it.id; clientSheetFromTree = true }
it.id in selection -> picked = selection - it.id
else -> picked = selection + it.id
}
},
onServer = { serverSheet = true },
modifier = Modifier.weight(1f),
reveal = reveal,
@@ -346,6 +380,10 @@ fun ServerScreen(
found = remember(treeHits) { treeHits.mapTo(HashSet()) { TreeRef(treeFind.channels, it) } },
foundCurrent = treeAt?.takeIf { it in treeHits }?.let { TreeRef(treeFind.channels, it) },
listState = treeList,
selected = selection,
onClientLongPress = if (server.canMoveClients || server.canKickFromChannel || server.canKickFromServer) {
{ picked = selection + it.id }
} else null,
onShowSelf = {
val path = tree.pathTo(state.selfClientId).orEmpty()
if (treeFiltering) filterCollapsed = filterCollapsed - path.toSet() else server.expand(path)
@@ -403,9 +441,9 @@ fun ServerScreen(
clientSheet = null
server.clientRef(id)?.let { ref -> toWhisperList = client.name to { it.clients.add(ref) } }
}) else null,
onMove = if (server.canMoveClients) ({ clientSheet = null; moving = id }) else null,
onMove = if (server.canMoveClients) ({ clientSheet = null; moving = setOf(id) }) else null,
onMoveToOwnChannel = if (server.canMoveClients && tree.channel(state.channelId)?.clients?.none { it.id == id } == true) {
{ server.moveClient(id, state.channelId); clientSheet = null }
{ server.moveClients(listOf(id), state.channelId); clientSheet = null }
} else null,
onFindInTree = if (clientSheetFromTree) null else ({
clientSheet = null
@@ -443,6 +481,18 @@ fun ServerScreen(
)
}
}
kickingSelection?.let { fromServer ->
val others = kickable(fromServer)
val whom = others.singleOrNull()?.let { tree.client(it)?.name } ?: "${others.size} clients"
KickPrompt(
if (fromServer) "Kick $whom from the server?" else "Kick $whom from the channel?",
onDismiss = { kickingSelection = null },
) { reason ->
kickingSelection = null
if (fromServer) server.kickFromServer(others, reason) else server.kickFromChannel(others, reason)
picked = emptySet()
}
}
joinLocked?.let { id ->
TextPrompt(
title = "Join ${tree.channel(id)?.name.orEmpty()}",
@@ -504,6 +554,28 @@ private const val MAX_CHAT_MATCHES = 5000
private fun next(at: Int, delta: Int, size: Int): Int =
if (at < 0) (if (delta > 0) 0 else size - 1) else Math.floorMod(at + delta, size)
/** How many clients are picked in the tree, and what may be done with them at once. */
@Composable
private fun SelectionBar(
count: Int,
onMove: (() -> Unit)?,
onMoveHere: (() -> Unit)?,
onKickChannel: (() -> Unit)?,
onKickServer: (() -> Unit)?,
onClear: () -> Unit,
) {
Surface(color = MaterialTheme.colorScheme.secondaryContainer) {
Row(Modifier.fillMaxWidth().padding(horizontal = 4.dp), verticalAlignment = Alignment.CenterVertically) {
IconButton(onClick = onClear) { Icon(Icons.Filled.Close, "Clear selection") }
Text("$count selected", Modifier.weight(1f), maxLines = 1, style = MaterialTheme.typography.bodyMedium)
onMove?.let { IconButton(onClick = it) { PackIcon("CHANNEL_SWITCH", "Move to…") } }
onMoveHere?.let { IconButton(onClick = it) { PackIcon("MOVE_CLIENT_TO_OWN_CHANNEL", "Move to my channel") } }
onKickChannel?.let { IconButton(onClick = it) { PackIcon("KICK_FROM_CHANNEL", "Kick from channel") } }
onKickServer?.let { IconButton(onClick = it) { PackIcon("KICK_FROM_SERVER", "Kick from server") } }
}
}
}
/** Says a channel is being picked for [name] to move to, until it is or [onCancel]. */
@Composable
private fun MovePrompt(name: String, onCancel: () -> Unit) {