Retain failed local messages across refresh
This commit is contained in:
1 parent
1f32f85190
commit
946249d994
2 files changed
+26
-2
No files matched your search
+24
-2
@@ -325,8 +325,10 @@ class RemoteOpenClawRepository(
|
||||
|
||||
suspend fun refreshMessages(sessionId: String) {
|
||||
val remoteMessages = api.getMessages(sessionId).map { dto -> dto.toDomainMessage() }
|
||||
messageStore = messageStore + (sessionId to remoteMessages)
|
||||
updateSessionPreview(sessionId, remoteMessages.lastOrNull())
|
||||
val localRetained = retainedLocalMessages(sessionId, remoteMessages)
|
||||
val merged = remoteMessages + localRetained
|
||||
messageStore = messageStore + (sessionId to merged)
|
||||
updateSessionPreview(sessionId, merged.lastOrNull())
|
||||
}
|
||||
|
||||
suspend fun sendMessageRemote(sessionId: String, text: String) {
|
||||
@@ -544,6 +546,26 @@ class RemoteOpenClawRepository(
|
||||
}
|
||||
}
|
||||
|
||||
private fun retainedLocalMessages(sessionId: String, remoteMessages: List<ChatMessage>): List<ChatMessage> {
|
||||
val localMessages = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") }
|
||||
return localMessages.filter { local ->
|
||||
when {
|
||||
local.kind == MessageKind.Text && local.role == MessageRole.User && local.status == "send-failed" -> {
|
||||
textRetryStore.putIfAbsent(local.id, TextRetryPayload(sessionId, local.text))
|
||||
remoteMessages.none { remote ->
|
||||
remote.role == MessageRole.User && remote.text == local.text
|
||||
}
|
||||
}
|
||||
local.kind == MessageKind.Attachment && local.status == "upload-failed" -> {
|
||||
remoteMessages.none { remote ->
|
||||
remote.kind == MessageKind.Attachment && remote.text == local.text
|
||||
}
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun mergeSnapshotWithLocalPending(
|
||||
remoteMessages: List<ChatMessage>,
|
||||
localPending: List<ChatMessage>,
|
||||
|
||||
Reference in new issue
Block a user