Skip to content

Commit 4c97aa1

Browse files
authored
feat(mobile): rename, delete, and create session groups on iOS and Android (#101234)
* feat(mobile): rename, delete, and create sidebar session groups on iOS and Android Group section headers on the iOS Command Center sessions screen and the Android sessions screen gain Rename/New/Delete group actions. Bulk ops enumerate every member (active + archived, explicit high list limit since the gateway caps an absent limit at 100 rows) and patch category per session; delete keeps sessions and moves them to Ungrouped. Known custom groups persist client-side (iOS UserDefaults, Android SharedPreferences) so empty groups stay visible as move targets. * chore(i18n): refresh native string inventory after rebase onto main
1 parent aed2482 commit 4c97aa1

13 files changed

Lines changed: 872 additions & 76 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 171 additions & 51 deletions
Large diffs are not rendered by default.

‎apps/android/app/src/main/java/ai/openclaw/app/MainViewModel.kt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class MainViewModel(
155155
val modelCatalogErrorText: StateFlow<String?> = runtimeState(initial = null) { it.modelCatalogErrorText }
156156
val modelFavorites: StateFlow<List<String>> = prefs.modelFavorites
157157
val modelRecents: StateFlow<List<String>> = prefs.modelRecents
158+
val sessionCustomGroups: StateFlow<List<String>> = prefs.sessionCustomGroups
158159
val talkSetupReadiness: StateFlow<GatewayTalkSetupReadiness> =
159160
runtimeState(initial = GatewayTalkSetupReadiness.unverified()) { it.talkSetupReadiness }
160161
val gatewayDefaultAgentId: StateFlow<String?> = runtimeState(initial = null) { it.gatewayDefaultAgentId }
@@ -765,6 +766,28 @@ class MainViewModel(
765766
ensureRuntime().deleteChatSession(key)
766767
}
767768

769+
/** Remembers a custom session group locally so it renders as an empty section. */
770+
fun addChatSessionGroup(name: String) {
771+
val trimmed = name.trim()
772+
if (trimmed.isEmpty()) return
773+
prefs.setSessionCustomGroups(prefs.sessionCustomGroups.value + trimmed)
774+
}
775+
776+
suspend fun renameChatSessionGroup(
777+
from: String,
778+
to: String,
779+
) {
780+
val stored = prefs.sessionCustomGroups.value
781+
// Web semantics: replace a stored name in place, otherwise remember the new name.
782+
prefs.setSessionCustomGroups(if (from in stored) stored.map { if (it == from) to else it } else stored + to)
783+
ensureRuntime().renameChatSessionGroup(from = from, to = to)
784+
}
785+
786+
suspend fun deleteChatSessionGroup(group: String) {
787+
prefs.setSessionCustomGroups(prefs.sessionCustomGroups.value.filterNot { it == group })
788+
ensureRuntime().dissolveChatSessionGroup(group)
789+
}
790+
768791
suspend fun forkChatSession(parentKey: String): String? = ensureRuntime().forkChatSession(parentKey)
769792

770793
suspend fun listWorkspaceFiles(

‎apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,17 @@ class NodeRuntime private constructor(
30573057
)
30583058
}
30593059

3060+
suspend fun renameChatSessionGroup(
3061+
from: String,
3062+
to: String,
3063+
) {
3064+
chat.renameSessionGroup(from = from, to = to)
3065+
}
3066+
3067+
suspend fun dissolveChatSessionGroup(group: String) {
3068+
chat.dissolveSessionGroup(group)
3069+
}
3070+
30603071
suspend fun deleteChatSession(key: String) {
30613072
chat.deleteSession(key)
30623073
}

‎apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class SecurePrefs(
6565
private const val appearanceThemeModeKey = "appearance.themeMode"
6666
private const val chatModelFavoritesKey = "chat.modelFavorites"
6767
private const val chatModelRecentsKey = "chat.modelRecents"
68+
private const val sessionCustomGroupsKey = "sessions.customGroups"
6869
private const val maxChatModelRecents = 5
6970
private const val gatewayCustomHeadersKeyPrefix = "gateway.customHeaders."
7071
}
@@ -215,6 +216,11 @@ class SecurePrefs(
215216
private val _modelRecents = MutableStateFlow(loadChatModelRefs(chatModelRecentsKey))
216217
val modelRecents: StateFlow<List<String>> = _modelRecents
217218

219+
// Custom session group names the user created locally; assigned groups also
220+
// persist server-side via the session category field (mirrors web localStorage).
221+
private val _sessionCustomGroups = MutableStateFlow(loadChatModelRefs(sessionCustomGroupsKey))
222+
val sessionCustomGroups: StateFlow<List<String>> = _sessionCustomGroups
223+
218224
fun setLastDiscoveredStableId(value: String) {
219225
val trimmed = value.trim()
220226
plainPrefs.edit { putString("gateway.lastDiscoveredStableID", trimmed) }
@@ -649,6 +655,12 @@ class SecurePrefs(
649655
_modelRecents.value = next
650656
}
651657

658+
fun setSessionCustomGroups(groups: List<String>) {
659+
val sanitized = groups.map(String::trim).filter { it.isNotEmpty() }.distinct()
660+
persistChatModelRefs(sessionCustomGroupsKey, sanitized)
661+
_sessionCustomGroups.value = sanitized
662+
}
663+
652664
private fun persistChatModelRefs(
653665
key: String,
654666
refs: List<String>,

‎apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,76 @@ class ChatController internal constructor(
389389
}
390390
}
391391

392+
/** Renames a session group everywhere: every member session moves to the new category. */
393+
suspend fun renameSessionGroup(
394+
from: String,
395+
to: String,
396+
) {
397+
val fromName = from.trim().takeIf { it.isNotEmpty() } ?: return
398+
val toName = to.trim().takeIf { it.isNotEmpty() } ?: return
399+
patchSessionGroupMembers(group = fromName, category = toName)
400+
}
401+
402+
/** Deletes a session group: member sessions are kept and move back to Ungrouped. */
403+
suspend fun dissolveSessionGroup(group: String) {
404+
val groupName = group.trim().takeIf { it.isNotEmpty() } ?: return
405+
patchSessionGroupMembers(group = groupName, category = null)
406+
}
407+
408+
private suspend fun patchSessionGroupMembers(
409+
group: String,
410+
category: String?,
411+
) {
412+
try {
413+
var firstError: Throwable? = null
414+
for (member in listSessionGroupMembers(group)) {
415+
try {
416+
val params =
417+
buildJsonObject {
418+
put("key", JsonPrimitive(member.key))
419+
put("category", category?.let(::JsonPrimitive) ?: JsonNull)
420+
}
421+
requestGateway("sessions.patch", params.toString())
422+
} catch (err: CancellationException) {
423+
throw err
424+
} catch (err: Throwable) {
425+
// Best-effort: one failed member patch must not strand the rest of the group.
426+
if (firstError == null) firstError = err
427+
}
428+
}
429+
firstError?.let { updateErrorText(it.message) }
430+
fetchSessionsForCurrentWindow()
431+
} catch (err: CancellationException) {
432+
throw err
433+
} catch (err: Throwable) {
434+
updateErrorText(err.message)
435+
}
436+
}
437+
438+
/**
439+
* Enumerates every session assigned to the group. The UI session list is windowed
440+
* (limited, archived either-or), so group mutations must not derive membership from
441+
* it. An absent limit is capped at 100 rows server-side, so both queries send an
442+
* explicit high bound; sessions.list filters archived rows either-or, hence two calls.
443+
*/
444+
private suspend fun listSessionGroupMembers(group: String): List<ChatSessionEntry> {
445+
val members = LinkedHashMap<String, ChatSessionEntry>()
446+
for (archived in listOf(false, true)) {
447+
val params =
448+
buildJsonObject {
449+
put("includeGlobal", JsonPrimitive(true))
450+
put("includeUnknown", JsonPrimitive(false))
451+
put("limit", JsonPrimitive(GROUP_MEMBER_FETCH_LIMIT))
452+
if (archived) put("archived", JsonPrimitive(true))
453+
}
454+
val rows = parseSessions(requestGateway("sessions.list", params.toString())).sessions
455+
for (row in rows) {
456+
if (row.category?.trim() == group && !members.containsKey(row.key)) members[row.key] = row
457+
}
458+
}
459+
return members.values.toList()
460+
}
461+
392462
suspend fun deleteSession(key: String) {
393463
val sessionKey = key.trim().takeIf { it.isNotEmpty() } ?: return
394464
try {
@@ -2222,6 +2292,9 @@ private enum class ChatMetadataLoadState {
22222292

22232293
private const val NEW_CHAT_SESSION_LABEL = "New chat"
22242294

2295+
// Group mutations enumerate whole stores; far past any realistic session count.
2296+
private const val GROUP_MEMBER_FETCH_LIMIT = 10_000
2297+
22252298
internal fun nextNewChatSessionLabel(sessions: List<ChatSessionEntry>): String {
22262299
val baseLabel = NEW_CHAT_SESSION_LABEL
22272300
val existingLabels =

‎apps/android/app/src/main/java/ai/openclaw/app/ui/SessionsScreen.kt‎

Lines changed: 133 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ internal fun SessionsScreen(
8989
var searchText by rememberSaveable { mutableStateOf("") }
9090
var searchResults by remember { mutableStateOf<List<ChatSessionEntry>>(emptyList()) }
9191
val searchQuery = searchText.trim()
92+
var renameGroupName by rememberSaveable { mutableStateOf<String?>(null) }
93+
var deleteGroupName by rememberSaveable { mutableStateOf<String?>(null) }
94+
var newGroupDialogVisible by rememberSaveable { mutableStateOf(false) }
9295
val visibleSessions =
9396
(if (searchQuery.isEmpty()) sessions else searchResults)
9497
.let { rows ->
@@ -106,10 +109,11 @@ internal fun SessionsScreen(
106109
rows.sortedBy { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
107110
}
108111
}
109-
val sections = groupSessionEntries(visibleSessions)
112+
val storedGroups by viewModel.sessionCustomGroups.collectAsState()
113+
val sections = groupSessionEntries(visibleSessions, knownGroups = storedGroups)
114+
// Stored group names stay offered as move targets even while they have no members.
110115
val categories =
111-
sessions
112-
.mapNotNull { it.category?.trim()?.takeIf(String::isNotEmpty) }
116+
(sessions.mapNotNull { it.category?.trim()?.takeIf(String::isNotEmpty) } + storedGroups)
113117
.distinctBy { it.lowercase() }
114118
.sortedWith(String.CASE_INSENSITIVE_ORDER)
115119

@@ -214,12 +218,21 @@ internal fun SessionsScreen(
214218
sections.forEachIndexed { index, section ->
215219
section.title?.let { title ->
216220
item(key = "section:$index:$title") {
217-
Text(
218-
text = title,
219-
style = ClawTheme.type.label,
220-
color = ClawTheme.colors.textMuted,
221-
modifier = Modifier.padding(top = 6.dp),
222-
)
221+
if (section.isCategory) {
222+
SessionGroupHeader(
223+
title = title,
224+
onRename = { renameGroupName = title },
225+
onNewGroup = { newGroupDialogVisible = true },
226+
onDelete = { deleteGroupName = title },
227+
)
228+
} else {
229+
Text(
230+
text = title,
231+
style = ClawTheme.type.label,
232+
color = ClawTheme.colors.textMuted,
233+
modifier = Modifier.padding(top = 6.dp),
234+
)
235+
}
223236
}
224237
}
225238
items(section.entries, key = { it.key }) { session ->
@@ -302,11 +315,70 @@ internal fun SessionsScreen(
302315
onDismiss = { groupSessionKey = null },
303316
onConfirm = { value ->
304317
groupSessionKey = null
318+
// Remember the name so the group survives locally even if the patch later empties it.
319+
viewModel.addChatSessionGroup(value)
305320
coroutineScope.launch { viewModel.patchChatSession(key = session.key, category = value.trim()) }
306321
},
307322
)
308323
}
309324

325+
renameGroupName?.let { group ->
326+
SessionTextDialog(
327+
title = "Rename group",
328+
stateKey = "group-rename:$group",
329+
initialValue = group,
330+
confirmLabel = "Rename",
331+
allowEmpty = false,
332+
onDismiss = { renameGroupName = null },
333+
onConfirm = { value ->
334+
renameGroupName = null
335+
val next = value.trim()
336+
if (next.isNotEmpty() && next != group) {
337+
coroutineScope.launch { viewModel.renameChatSessionGroup(from = group, to = next) }
338+
}
339+
},
340+
)
341+
}
342+
343+
if (newGroupDialogVisible) {
344+
SessionTextDialog(
345+
title = "New group",
346+
stateKey = "group-new",
347+
initialValue = "",
348+
confirmLabel = "Create",
349+
allowEmpty = false,
350+
onDismiss = { newGroupDialogVisible = false },
351+
onConfirm = { value ->
352+
newGroupDialogVisible = false
353+
viewModel.addChatSessionGroup(value)
354+
},
355+
)
356+
}
357+
358+
deleteGroupName?.let { group ->
359+
AlertDialog(
360+
onDismissRequest = { deleteGroupName = null },
361+
containerColor = ClawTheme.colors.surfaceRaised,
362+
title = { Text("Delete group?", style = ClawTheme.type.section, color = ClawTheme.colors.text) },
363+
text = { Text("Sessions in \"$group\" are kept and move back to Ungrouped.", style = ClawTheme.type.body, color = ClawTheme.colors.textMuted) },
364+
confirmButton = {
365+
TextButton(
366+
onClick = {
367+
deleteGroupName = null
368+
coroutineScope.launch { viewModel.deleteChatSessionGroup(group) }
369+
},
370+
) {
371+
Text("Delete", color = ClawTheme.colors.danger)
372+
}
373+
},
374+
dismissButton = {
375+
TextButton(onClick = { deleteGroupName = null }) {
376+
Text("Cancel")
377+
}
378+
},
379+
)
380+
}
381+
310382
sessions.firstOrNull { it.key == deleteSessionKey }?.let { session ->
311383
AlertDialog(
312384
onDismissRequest = { deleteSessionKey = null },
@@ -529,6 +601,43 @@ private fun SessionRow(
529601
}
530602
}
531603

604+
/** Category section header; long-press opens the group management menu. */
605+
@Composable
606+
private fun SessionGroupHeader(
607+
title: String,
608+
onRename: () -> Unit,
609+
onNewGroup: () -> Unit,
610+
onDelete: () -> Unit,
611+
) {
612+
var menuExpanded by remember { mutableStateOf(false) }
613+
Box(modifier = Modifier.padding(top = 6.dp)) {
614+
Text(
615+
text = title,
616+
style = ClawTheme.type.label,
617+
color = ClawTheme.colors.textMuted,
618+
modifier =
619+
Modifier.combinedClickable(
620+
onClick = {},
621+
onLongClick = { menuExpanded = true },
622+
),
623+
)
624+
DropdownMenu(expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
625+
SessionMenuItem("Rename group…") {
626+
menuExpanded = false
627+
onRename()
628+
}
629+
SessionMenuItem("New group…") {
630+
menuExpanded = false
631+
onNewGroup()
632+
}
633+
SessionMenuItem("Delete group…") {
634+
menuExpanded = false
635+
onDelete()
636+
}
637+
}
638+
}
639+
}
640+
532641
@Composable
533642
private fun SessionMenuItem(
534643
text: String,
@@ -618,23 +727,32 @@ private enum class SessionFilter {
618727
internal data class SessionSection(
619728
val title: String?,
620729
val entries: List<ChatSessionEntry>,
730+
// Only custom category sections expose group actions; "Pinned"/"Ungrouped" are structural.
731+
val isCategory: Boolean = false,
621732
)
622733

623734
/** Groups pinned sessions once, followed by alphabetical categories and remaining sessions. */
624-
internal fun groupSessionEntries(entries: List<ChatSessionEntry>): List<SessionSection> {
735+
internal fun groupSessionEntries(
736+
entries: List<ChatSessionEntry>,
737+
knownGroups: List<String> = emptyList(),
738+
): List<SessionSection> {
625739
if (entries.isEmpty()) return emptyList()
626740
val pinned = entries.filter { it.pinned == true }
627741
val remaining = entries.filterNot { it.pinned == true }
628-
val categorized = remaining.filter { !it.category.isNullOrBlank() }
742+
val populated = remaining.filter { !it.category.isNullOrBlank() }.groupBy { it.category.orEmpty().trim() }
743+
// Stored-but-empty groups still render so they stay visible as move targets.
744+
val emptyKnown =
745+
knownGroups
746+
.mapNotNull { it.trim().takeIf(String::isNotEmpty) }
747+
.distinctBy { it.lowercase() }
748+
.filterNot { name -> populated.keys.any { it.equals(name, ignoreCase = true) } }
629749
val categories =
630-
categorized
631-
.groupBy { it.category.orEmpty().trim() }
632-
.toList()
750+
(populated.toList() + emptyKnown.map { it to emptyList<ChatSessionEntry>() })
633751
.sortedBy { it.first.lowercase() }
634752
val ungrouped = remaining.filter { it.category.isNullOrBlank() }
635753
return buildList {
636754
if (pinned.isNotEmpty()) add(SessionSection(title = "Pinned", entries = pinned))
637-
categories.forEach { (category, sessions) -> add(SessionSection(title = category, entries = sessions)) }
755+
categories.forEach { (category, sessions) -> add(SessionSection(title = category, entries = sessions, isCategory = true)) }
638756
if (ungrouped.isNotEmpty()) {
639757
add(SessionSection(title = "Ungrouped".takeIf { categories.isNotEmpty() }, entries = ungrouped))
640758
}

0 commit comments

Comments
 (0)