Skip to content

Commit 657b6e8

Browse files
feat(android): pin gateway-backed session search in the sidebar (#124338)
* fix-android-chat-session-picker * fix-search-all-android-sessions * fix-native-i18n-inventory * fix-android-share-session-browser-policy * fix(android): show loading during session search * refactor(android): move gateway-backed session search into the pinned sidebar The sidebar header and search field no longer scroll away: they sit above the scrolling sections, and the search field is always visible instead of hidden behind a toggle. Queries now run through the shared session-browser search state (debounced gateway search with offline fallback) instead of a local filter over cached rows, and matching threads replace the section list while a query is active. The in-chat bottom-sheet picker is removed: the compact switcher's All button navigates straight to the Sessions screen again, and the sidebar owns in-context session search. The shared rememberSessionBrowserSearchState extraction from the Sessions screen is kept and gains the sidebar as its second consumer. * style(android): fix sidebar import ordering for ktlint --------- Co-authored-by: IWhatsskill <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 42a4625 commit 657b6e8

5 files changed

Lines changed: 247 additions & 221 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,23 @@ internal fun SessionsScreen(
103103
var deleteSessionTarget by
104104
rememberSaveable(stateSaver = SessionActionTargetSaver) { mutableStateOf<SessionActionTarget?>(null) }
105105
var searchText by rememberSaveable { mutableStateOf("") }
106-
var searchResults by remember { mutableStateOf<List<ChatSessionEntry>>(emptyList()) }
107-
var searchLoading by remember { mutableStateOf(false) }
108-
val searchQuery = searchText.trim()
109106
var renameGroupName by rememberSaveable { mutableStateOf<String?>(null) }
110107
var deleteGroupName by rememberSaveable { mutableStateOf<String?>(null) }
111108
var newGroupDialogVisible by rememberSaveable { mutableStateOf(false) }
109+
val searchState =
110+
rememberSessionBrowserSearchState(
111+
viewModel = viewModel,
112+
sessions = sessions,
113+
query = searchText,
114+
archived = filter == SessionFilter.Archived,
115+
)
112116
val visibleSessions =
113-
(if (searchQuery.isEmpty()) sessions else searchResults)
114-
.let { rows ->
115-
when (filter) {
116-
SessionFilter.Recent -> rows.filter { it.archived != true }
117-
SessionFilter.Current -> rows.filter { it.key == chatSessionKey && it.archived != true }
118-
// Gate on the entry's own archived flag so the pre-toggle active list can
119-
// never render with archived-only actions while the refetch is in flight.
120-
SessionFilter.Archived -> rows.filter { it.archived == true }
121-
}
122-
}.let { rows ->
123-
if (recentFirst) {
124-
rows.sortedByDescending { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
125-
} else {
126-
rows.sortedBy { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
127-
}
128-
}
117+
resolveSessionBrowserEntries(
118+
entries = searchState.entries,
119+
currentSessionKey = chatSessionKey,
120+
filter = filter,
121+
recentFirst = recentFirst,
122+
)
129123
val storedGroups by viewModel.sessionCustomGroups.collectAsState()
130124
val sections = groupSessionEntries(visibleSessions, knownGroups = storedGroups)
131125
// Stored group names stay offered as move targets even while they have no members.
@@ -146,30 +140,6 @@ internal fun SessionsScreen(
146140
}
147141
}
148142

149-
// Keyed on the live session list too: row actions (pin/rename/archive/delete)
150-
// refresh live state, which re-runs the search so results never go stale.
151-
LaunchedEffect(searchQuery, filter, sessions) {
152-
if (searchQuery.isEmpty()) {
153-
searchResults = emptyList()
154-
searchLoading = false
155-
return@LaunchedEffect
156-
}
157-
searchResults = emptyList()
158-
searchLoading = true
159-
try {
160-
// Debounce keystrokes; the key change cancels superseded fetches, and the
161-
// controller falls back to local filtering when the gateway is unreachable.
162-
delay(250)
163-
searchResults =
164-
viewModel.fetchChatSessionList(
165-
search = searchQuery,
166-
archived = filter == SessionFilter.Archived,
167-
)
168-
} finally {
169-
searchLoading = false
170-
}
171-
}
172-
173143
ClawScaffold(
174144
contentPadding = PaddingValues(start = 16.dp, top = 10.dp, end = 16.dp, bottom = 4.dp),
175145
contentWindowInsets = WindowInsets.safeDrawing,
@@ -306,7 +276,7 @@ internal fun SessionsScreen(
306276
modifier = Modifier.fillParentMaxHeight(0.56f).fillMaxWidth(),
307277
contentAlignment = Alignment.Center,
308278
) {
309-
when (sessionEmptyMode(searchQuery, searchLoading)) {
279+
when (sessionEmptyMode(searchState.query, searchState.loading)) {
310280
SessionEmptyMode.SearchLoading -> ClawLoadingState(title = nativeString("Searching threads"))
311281
SessionEmptyMode.SearchNoMatches ->
312282
ClawEmptyState(
@@ -874,12 +844,82 @@ private fun SessionMiniTag(text: String) {
874844
}
875845
}
876846

877-
private enum class SessionFilter {
847+
internal enum class SessionFilter {
878848
Recent,
879849
Current,
880850
Archived,
881851
}
882852

853+
internal data class SessionBrowserSearchState(
854+
val query: String,
855+
val entries: List<ChatSessionEntry>,
856+
val loading: Boolean,
857+
)
858+
859+
/** Canonical debounced, gateway-backed search state shared by session browser surfaces. */
860+
@Composable
861+
internal fun rememberSessionBrowserSearchState(
862+
viewModel: MainViewModel,
863+
sessions: List<ChatSessionEntry>,
864+
query: String,
865+
archived: Boolean,
866+
): SessionBrowserSearchState {
867+
val normalizedQuery = query.trim()
868+
var searchResults by remember { mutableStateOf<List<ChatSessionEntry>>(emptyList()) }
869+
var searchLoading by remember { mutableStateOf(false) }
870+
871+
// Keyed on the live list too: row mutations refresh sessions and re-run an active search.
872+
LaunchedEffect(normalizedQuery, archived, sessions) {
873+
if (normalizedQuery.isEmpty()) {
874+
searchResults = emptyList()
875+
searchLoading = false
876+
return@LaunchedEffect
877+
}
878+
searchResults = emptyList()
879+
searchLoading = true
880+
try {
881+
// Key changes cancel superseded debounce/fetch work. The controller owns
882+
// gateway search plus the offline local-filter fallback.
883+
delay(250)
884+
searchResults =
885+
viewModel.fetchChatSessionList(
886+
search = normalizedQuery,
887+
archived = archived,
888+
)
889+
} finally {
890+
searchLoading = false
891+
}
892+
}
893+
894+
return SessionBrowserSearchState(
895+
query = normalizedQuery,
896+
entries = if (normalizedQuery.isEmpty()) sessions else searchResults,
897+
loading = searchLoading,
898+
)
899+
}
900+
901+
/** Applies the canonical active/current/archived filter and chronological ordering. */
902+
internal fun resolveSessionBrowserEntries(
903+
entries: List<ChatSessionEntry>,
904+
currentSessionKey: String,
905+
filter: SessionFilter,
906+
recentFirst: Boolean,
907+
): List<ChatSessionEntry> {
908+
val filtered =
909+
when (filter) {
910+
SessionFilter.Recent -> entries.filter { it.archived != true }
911+
SessionFilter.Current -> entries.filter { it.key == currentSessionKey && it.archived != true }
912+
// Gate on the entry's own archived flag so a pre-toggle active list can
913+
// never render with archived-only actions while a refetch is in flight.
914+
SessionFilter.Archived -> entries.filter { it.archived == true }
915+
}
916+
return if (recentFirst) {
917+
filtered.sortedByDescending { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
918+
} else {
919+
filtered.sortedBy { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
920+
}
921+
}
922+
883923
internal fun sessionListSubtitle(
884924
session: ChatSessionEntry,
885925
fallback: String,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ fun ShellScreen(
279279
onSelectDestination = selectSidebarDestination,
280280
drawerContent = {
281281
OpenClawSidebar(
282+
viewModel = viewModel,
282283
agents = gatewayAgents,
283284
selectedAgentId = chatSessionOwnerAgentId ?: gatewayDefaultAgentId,
284285
sessions = chatSessions,

0 commit comments

Comments
 (0)