Stabilize session sorting with sort keys
This commit is contained in:
1 parent
439c0a4a7b
commit
a4a6632707
2 files changed
+29
-1
No files matched your search
+27
@@ -67,6 +67,7 @@ class RemoteOpenClawRepository(
|
|||||||
private var recentSessionId by mutableStateOf<String?>(null)
|
private var recentSessionId by mutableStateOf<String?>(null)
|
||||||
private var messageStore by mutableStateOf<Map<String, List<ChatMessage>>>(emptyMap())
|
private var messageStore by mutableStateOf<Map<String, List<ChatMessage>>>(emptyMap())
|
||||||
private var streamStatusStore by mutableStateOf<Map<String, String>>(emptyMap())
|
private var streamStatusStore by mutableStateOf<Map<String, String>>(emptyMap())
|
||||||
|
private val sessionSortKeyStore = mutableMapOf<String, Long>()
|
||||||
private val attachmentRetryStore = mutableMapOf<String, AttachmentRetryPayload>()
|
private val attachmentRetryStore = mutableMapOf<String, AttachmentRetryPayload>()
|
||||||
private val attachmentOpenStore = mutableMapOf<String, AttachmentOpenPayload>()
|
private val attachmentOpenStore = mutableMapOf<String, AttachmentOpenPayload>()
|
||||||
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
||||||
@@ -81,6 +82,7 @@ class RemoteOpenClawRepository(
|
|||||||
override fun hydrateOverview(snapshot: OverviewSnapshot) {
|
override fun hydrateOverview(snapshot: OverviewSnapshot) {
|
||||||
availableAgents = snapshot.availableAgents
|
availableAgents = snapshot.availableAgents
|
||||||
sessions = snapshot.sessions.map { it.toDomain() }
|
sessions = snapshot.sessions.map { it.toDomain() }
|
||||||
|
rebuildSessionSortKeys(sessions)
|
||||||
status = snapshot.status.toDomain()
|
status = snapshot.status.toDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +301,7 @@ class RemoteOpenClawRepository(
|
|||||||
|
|
||||||
suspend fun refreshSessions() {
|
suspend fun refreshSessions() {
|
||||||
sessions = api.getSessions().map { dto -> dto.toDomain() }
|
sessions = api.getSessions().map { dto -> dto.toDomain() }
|
||||||
|
rebuildSessionSortKeys(sessions)
|
||||||
resortSessions(prioritizeId = recentSessionId)
|
resortSessions(prioritizeId = recentSessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,6 +532,7 @@ class RemoteOpenClawRepository(
|
|||||||
val existing = sessions.firstOrNull { it.id == sessionId }
|
val existing = sessions.firstOrNull { it.id == sessionId }
|
||||||
val fallbackUpdatedAt = existing?.updatedAt ?: "刚刚"
|
val fallbackUpdatedAt = existing?.updatedAt ?: "刚刚"
|
||||||
val updatedAt = lastMessage?.createdAt ?: fallbackUpdatedAt
|
val updatedAt = lastMessage?.createdAt ?: fallbackUpdatedAt
|
||||||
|
sessionSortKeyStore[sessionId] = computeSessionSortKey(sessionId, updatedAt)
|
||||||
sessions = sessions.map { session ->
|
sessions = sessions.map { session ->
|
||||||
if (session.id == sessionId) {
|
if (session.id == sessionId) {
|
||||||
session.copy(
|
session.copy(
|
||||||
@@ -648,10 +652,33 @@ class RemoteOpenClawRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun rebuildSessionSortKeys(items: List<SessionSummary>) {
|
||||||
|
val total = items.size.toLong()
|
||||||
|
items.forEachIndexed { index, session ->
|
||||||
|
val fallback = (total - index).coerceAtLeast(1L)
|
||||||
|
sessionSortKeyStore[session.id] = parseDisplaySortKey(session.updatedAt) ?: fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun computeSessionSortKey(sessionId: String, updatedAt: String): Long {
|
||||||
|
return when (updatedAt) {
|
||||||
|
"现在", "刚刚" -> (sessionSortKeyStore.values.maxOrNull() ?: 0L) + 1L
|
||||||
|
else -> parseDisplaySortKey(updatedAt) ?: (sessionSortKeyStore[sessionId] ?: 0L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseDisplaySortKey(value: String?): Long? {
|
||||||
|
val text = value?.trim().orEmpty()
|
||||||
|
if (text.isBlank()) return null
|
||||||
|
val digits = text.filter(Char::isDigit)
|
||||||
|
return if (digits.length >= 12) digits.take(12).toLongOrNull() else null
|
||||||
|
}
|
||||||
|
|
||||||
private fun resortSessions(prioritizeId: String?) {
|
private fun resortSessions(prioritizeId: String?) {
|
||||||
sessions = sessions.sortedWith(
|
sessions = sessions.sortedWith(
|
||||||
compareByDescending<SessionSummary> { it.id == prioritizeId }
|
compareByDescending<SessionSummary> { it.id == prioritizeId }
|
||||||
.thenByDescending { it.isPinned }
|
.thenByDescending { it.isPinned }
|
||||||
|
.thenByDescending { sessionSortKeyStore[it.id] ?: 0L }
|
||||||
.thenByDescending { it.updatedAt }
|
.thenByDescending { it.updatedAt }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ Android/iOS App
|
|||||||
|
|
||||||
结论:**可用,但后面还要继续稳固。**
|
结论:**可用,但后面还要继续稳固。**
|
||||||
|
|
||||||
补充:BFF 已开始补 diff 细节稳定性。当前已修一类典型误判——当同一条消息在一次轮询里既发生文本增长、又发生状态/类型元数据变化时,BFF 现在会同时补发 `message.completed`,避免前端只收到 delta 后停留在半完成状态。并且,BFF 也开始收敛“新消息一次性出现”的事件噪音:不再对所有新消息都连发 `started + completed`,而是仅对明显仍在进行中的消息发 `started`,其余直接发 `completed`。另外,消息消失时已不再默认整包 `session.snapshot` 重刷,而是优先发精确的 `message.removed` 事件,由 App 按 id 删除对应消息;同时 App 的 session 列表摘要也会随精确删除同步回退,不再顽固保留已被删掉的最后一条消息摘要。并且,App 现在会在本地 queued / thinking 占位写入和 SSE `message.started` 首帧到达时,同步刷新 session 列表摘要,减少“聊天页已变但列表还停在旧内容”的延迟。
|
补充:BFF 已开始补 diff 细节稳定性。当前已修一类典型误判——当同一条消息在一次轮询里既发生文本增长、又发生状态/类型元数据变化时,BFF 现在会同时补发 `message.completed`,避免前端只收到 delta 后停留在半完成状态。并且,BFF 也开始收敛“新消息一次性出现”的事件噪音:不再对所有新消息都连发 `started + completed`,而是仅对明显仍在进行中的消息发 `started`,其余直接发 `completed`。另外,消息消失时已不再默认整包 `session.snapshot` 重刷,而是优先发精确的 `message.removed` 事件,由 App 按 id 删除对应消息;同时 App 的 session 列表摘要也会随精确删除同步回退,不再顽固保留已被删掉的最后一条消息摘要。并且,App 现在会在本地 queued / thinking 占位写入和 SSE `message.started` 首帧到达时,同步刷新 session 列表摘要,减少“聊天页已变但列表还停在旧内容”的延迟。session 列表排序也开始从“直接比较显示字符串”过渡到独立维护的时间 sort key,降低 `现在` / `刚刚` / 格式化时间混排时的排序抖动。
|
||||||
|
|
||||||
### 3.2 附件能力
|
### 3.2 附件能力
|
||||||
|
|
||||||
@@ -393,3 +393,4 @@ Android/iOS App
|
|||||||
- 2026-03-07:BFF/App 联动补 `message.removed`:当某条消息在新一轮 history 中消失时,BFF 优先发精确删除事件,App 按 id 从当前时间线里移除对应消息;只有极端场景(如整个会话消息清空)才再补空 snapshot。这样比“消息一消失就整包 snapshot”更细、更稳,也更像真实事件流。
|
- 2026-03-07:BFF/App 联动补 `message.removed`:当某条消息在新一轮 history 中消失时,BFF 优先发精确删除事件,App 按 id 从当前时间线里移除对应消息;只有极端场景(如整个会话消息清空)才再补空 snapshot。这样比“消息一消失就整包 snapshot”更细、更稳,也更像真实事件流。
|
||||||
- 2026-03-07:App 补 session 摘要一致性:当 SSE 精确删除命中最后一条消息时,会话列表摘要不再保留旧值,而是同步清空/回退到当前真实最后一条,避免“聊天删了但列表还显示旧摘要”。
|
- 2026-03-07:App 补 session 摘要一致性:当 SSE 精确删除命中最后一条消息时,会话列表摘要不再保留旧值,而是同步清空/回退到当前真实最后一条,避免“聊天删了但列表还显示旧摘要”。
|
||||||
- 2026-03-07:继续补 session 摘要一致性:本地发送插入 queued/thinking 占位,以及 SSE `message.started` 首帧到达时,会话列表摘要现在会立即同步刷新;同时摘要优先忽略 `local-thinking-*` 占位,尽量展示真实最后一条可读消息。
|
- 2026-03-07:继续补 session 摘要一致性:本地发送插入 queued/thinking 占位,以及 SSE `message.started` 首帧到达时,会话列表摘要现在会立即同步刷新;同时摘要优先忽略 `local-thinking-*` 占位,尽量展示真实最后一条可读消息。
|
||||||
|
- 2026-03-07:开始补 session 列表排序稳定性:App 不再只按 `updatedAt` 显示字符串排序,而是额外维护独立的 session sort key;`现在` / `刚刚` 会映射为递增排序值,格式化时间则尽量解析成稳定数值,减少列表在本地 pending / SSE 更新下的错序与抖动。
|
||||||
Reference in new issue
Block a user