diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt index e20cc8e..6f3672c 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt @@ -79,3 +79,29 @@ fun ChatMessage.isLocalPendingActive(): Boolean { fun ChatMessage.isLocalFailure(): Boolean { return localMessagePhase() == LocalMessagePhase.Failed } + +fun textStatusForLocalPhase( + phase: LocalMessagePhase, + fallback: String = "queued", +): String { + return when (phase) { + LocalMessagePhase.QueueProcessing -> "queue-draining" + LocalMessagePhase.AutoRetrying -> "retrying-auto" + LocalMessagePhase.ManualProcessing -> "queued" + LocalMessagePhase.Failed -> "send-failed" + else -> fallback + } +} + +fun attachmentStatusForLocalPhase( + phase: LocalMessagePhase, + fallback: String = "uploading", +): String { + return when (phase) { + LocalMessagePhase.QueueProcessing -> "queue-draining" + LocalMessagePhase.ManualProcessing -> "uploading" + LocalMessagePhase.Failed -> "upload-failed" + LocalMessagePhase.Completed -> "uploaded" + else -> fallback + } +} diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt index 1baf202..8e4cd2c 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -3,8 +3,11 @@ package cn.xiaobai.openclawapp.data import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import cn.xiaobai.openclawapp.data.LocalMessagePhase +import cn.xiaobai.openclawapp.data.attachmentStatusForLocalPhase import cn.xiaobai.openclawapp.data.isLocalFailure import cn.xiaobai.openclawapp.data.isLocalPendingActive +import cn.xiaobai.openclawapp.data.textStatusForLocalPhase import cn.xiaobai.openclawapp.network.MobileGatewayApi import cn.xiaobai.openclawapp.network.SessionSummaryDto import cn.xiaobai.openclawapp.network.SessionStreamEvent @@ -234,7 +237,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = text, createdAt = "现在", - status = "queued", + status = textStatusForLocalPhase(LocalMessagePhase.ManualProcessing), ), ChatMessage( id = "local-thinking-$sessionId-${withoutThinking.size + 2}", @@ -279,7 +282,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = fileName, createdAt = "现在", - status = "queue-draining", + status = attachmentStatusForLocalPhase(LocalMessagePhase.QueueProcessing), kind = MessageKind.Attachment, contentType = contentType, sizeBytes = bytes.size, @@ -298,7 +301,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = remote.fileName, createdAt = remote.queuedAt, - status = "uploaded", + status = attachmentStatusForLocalPhase(LocalMessagePhase.Completed), kind = MessageKind.Attachment, contentType = remote.contentType, sizeBytes = remote.sizeBytes, @@ -316,7 +319,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = fileName, createdAt = "刚刚", - status = "upload-failed", + status = attachmentStatusForLocalPhase(LocalMessagePhase.Failed), kind = MessageKind.Attachment, contentType = contentType, sizeBytes = bytes.size, @@ -336,9 +339,10 @@ class RemoteOpenClawRepository( private suspend fun retryAttachmentInternal(sessionId: String, messageId: String, fromQueueDrain: Boolean) { val payload = attachmentRetryStore[messageId] ?: return val current = messageStore[sessionId].orEmpty() + val phase = if (fromQueueDrain) LocalMessagePhase.QueueProcessing else LocalMessagePhase.ManualProcessing val uploading = current.map { msg -> if (msg.id == messageId) msg.copy( - status = if (fromQueueDrain) "queue-draining" else "uploading", + status = attachmentStatusForLocalPhase(phase), retryable = false, createdAt = "现在", ) else msg @@ -357,7 +361,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = remote.fileName, createdAt = remote.queuedAt, - status = "uploaded", + status = attachmentStatusForLocalPhase(LocalMessagePhase.Completed), kind = MessageKind.Attachment, contentType = remote.contentType, sizeBytes = remote.sizeBytes, @@ -375,7 +379,7 @@ class RemoteOpenClawRepository( role = MessageRole.User, text = payload.fileName, createdAt = "刚刚", - status = "upload-failed", + status = attachmentStatusForLocalPhase(LocalMessagePhase.Failed), kind = MessageKind.Attachment, contentType = payload.contentType, sizeBytes = payload.bytes.size, @@ -503,13 +507,14 @@ class RemoteOpenClawRepository( val payload = textRetryStore[messageId] ?: return val current = messageStore[sessionId].orEmpty() val isAutoRetry = messageId in autoRetryMessageIds + val phase = when { + fromQueueDrain -> LocalMessagePhase.QueueProcessing + isAutoRetry -> LocalMessagePhase.AutoRetrying + else -> LocalMessagePhase.ManualProcessing + } val retried = current.map { msg -> if (msg.id == messageId) msg.copy( - status = when { - fromQueueDrain -> "queue-draining" - isAutoRetry -> "retrying-auto" - else -> "queued" - }, + status = textStatusForLocalPhase(phase), retryable = false, createdAt = "现在", ) else msg @@ -801,7 +806,7 @@ class RemoteOpenClawRepository( ) message.copy( id = failedId, - status = "send-failed", + status = textStatusForLocalPhase(LocalMessagePhase.Failed), retryable = true, createdAt = "刚刚", ) diff --git a/docs/MVP_PROGRESS.md b/docs/MVP_PROGRESS.md index 501e20b..a552e46 100644 --- a/docs/MVP_PROGRESS.md +++ b/docs/MVP_PROGRESS.md @@ -204,6 +204,7 @@ Android/iOS App - [x] 已补本地 pending 保留逻辑:refresh / SSE snapshot 不再只保留 `queued` 文本;`queue-draining` / `retrying-auto` / 本地附件 pending 也会保留,避免队列处理中消息被快照冲掉 - [x] 已抽出本地 pending 派生状态:新增 `LocalMessagePhase` 与 `localMessagePhase()` / `isLocalPendingActive()`,开始统一 UI 与本地保留逻辑对 pending 状态的判断,减少散落的字符串分支 - [x] 缓存恢复逻辑也已开始接入派生状态:本地文本若在 `queue-draining` / `retrying-auto` 时被杀掉,重启后会统一恢复为可手动重试的 `send-failed`;附件同理会统一回落为 `upload-failed` +- [x] Repository 的核心写状态入口已开始复用派生状态映射:新增 `textStatusForLocalPhase()` / `attachmentStatusForLocalPhase()`,用于统一写入手动处理中、队列处理中、失败态、完成态,减少散落的状态字符串 - [ ] 还没有完整的离线发送队列(当前已覆盖文本 + 附件,但还没有更完整的网络感知、后台 drain 与统一淘汰策略) - [ ] 还没有真正基于网络恢复信号的自动补发