Keep cached session previews when available

This commit is contained in:
OpenClaw committed 2026-03-07 19:42:05 +08:00
1 parent 9146b7a863
commit 32d10933ef
3 files changed
+25 -17

No files matched your search

@@ -458,7 +458,10 @@ class RemoteOpenClawRepository(
}
suspend fun refreshSessions() {
sessions = api.getSessions().map { dto -> dto.toDomain() }
val existingPreviews = sessions.associateBy({ it.id }, { it.lastMessage })
sessions = api.getSessions().map { dto ->
dto.toDomain(existingLastMessage = existingPreviews[dto.id])
}
rebuildSessionSortKeysFromSessions(sessions)
resortSessions(prioritizeId = recentSessionId)
}
@@ -1107,11 +1110,11 @@ class RemoteOpenClawRepository(
)
}
private fun SessionSummaryDto.toDomain(): SessionSummary {
private fun SessionSummaryDto.toDomain(existingLastMessage: String? = null): SessionSummary {
return SessionSummary(
id = id,
title = title,
lastMessage = lastMessage ?: "",
lastMessage = (lastMessage ?: existingLastMessage).orEmpty(),
updatedAt = updatedAt,
streamStatus = streamStatusStore[id],
)
@@ -123,13 +123,15 @@ fun SessionListScreen(
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text("最近访问", style = MaterialTheme.typography.labelLarge)
Text(recentSession.title, style = MaterialTheme.typography.titleMedium, maxLines = 1)
Text(
recentSession.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
recentSession.lastMessage.takeIf { it.isNotBlank() }?.let { summary ->
Text(
summary,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
}
}
TextButton(onClick = { onOpenSession(recentSession.id) }) {
Text("继续")
@@ -218,13 +220,15 @@ private fun SessionRow(
}
}
Text(
text = session.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
session.lastMessage.takeIf { it.isNotBlank() }?.let { summary ->
Text(
text = summary,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
}
Row(
modifier = Modifier.fillMaxWidth(),