Show stream status in session list
This commit is contained in:
1 parent
151d665061
commit
ae0bf93ed1
3 files changed
+27
No files matched your search
@@ -13,6 +13,7 @@ data class SessionSummary(
|
|||||||
val updatedAt: String,
|
val updatedAt: String,
|
||||||
val isPinned: Boolean = false,
|
val isPinned: Boolean = false,
|
||||||
val unreadCount: Int = 0,
|
val unreadCount: Int = 0,
|
||||||
|
val streamStatus: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ChatMessage(
|
data class ChatMessage(
|
||||||
|
|||||||
+14
@@ -164,10 +164,12 @@ class RemoteOpenClawRepository(
|
|||||||
private fun subscribeSessionStream(sessionId: String) {
|
private fun subscribeSessionStream(sessionId: String) {
|
||||||
streamJob?.cancel()
|
streamJob?.cancel()
|
||||||
streamStatusStore = streamStatusStore + (sessionId to "connecting")
|
streamStatusStore = streamStatusStore + (sessionId to "connecting")
|
||||||
|
syncSessionStreamStatus(sessionId)
|
||||||
streamJob = streamScope.launch {
|
streamJob = streamScope.launch {
|
||||||
while (currentCoroutineContext().isActive) {
|
while (currentCoroutineContext().isActive) {
|
||||||
try {
|
try {
|
||||||
streamStatusStore = streamStatusStore + (sessionId to "live")
|
streamStatusStore = streamStatusStore + (sessionId to "live")
|
||||||
|
syncSessionStreamStatus(sessionId)
|
||||||
sseStream.connect(sessionId).collect { event ->
|
sseStream.connect(sessionId).collect { event ->
|
||||||
when (event) {
|
when (event) {
|
||||||
is SessionStreamEvent.Snapshot -> {
|
is SessionStreamEvent.Snapshot -> {
|
||||||
@@ -244,6 +246,7 @@ class RemoteOpenClawRepository(
|
|||||||
val dto = event.payload
|
val dto = event.payload
|
||||||
if (!dto.recoverable) {
|
if (!dto.recoverable) {
|
||||||
streamStatusStore = streamStatusStore + (sessionId to "failed")
|
streamStatusStore = streamStatusStore + (sessionId to "failed")
|
||||||
|
syncSessionStreamStatus(sessionId)
|
||||||
messageStore = messageStore + (
|
messageStore = messageStore + (
|
||||||
sessionId to (messageStore[sessionId].orEmpty() + ChatMessage(
|
sessionId to (messageStore[sessionId].orEmpty() + ChatMessage(
|
||||||
id = "stream-failed-$sessionId",
|
id = "stream-failed-$sessionId",
|
||||||
@@ -258,6 +261,7 @@ class RemoteOpenClawRepository(
|
|||||||
return@collect
|
return@collect
|
||||||
}
|
}
|
||||||
streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
|
streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
|
||||||
|
syncSessionStreamStatus(sessionId)
|
||||||
// recoverable: will retry via outer while loop
|
// recoverable: will retry via outer while loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,6 +270,7 @@ class RemoteOpenClawRepository(
|
|||||||
throw e
|
throw e
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
|
streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
|
||||||
|
syncSessionStreamStatus(sessionId)
|
||||||
delay(1500)
|
delay(1500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,6 +291,7 @@ class RemoteOpenClawRepository(
|
|||||||
lastMessage = preview.ifBlank { session.lastMessage },
|
lastMessage = preview.ifBlank { session.lastMessage },
|
||||||
updatedAt = updatedAt,
|
updatedAt = updatedAt,
|
||||||
unreadCount = 0,
|
unreadCount = 0,
|
||||||
|
streamStatus = streamStatusStore[sessionId],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
session
|
session
|
||||||
@@ -335,6 +341,13 @@ class RemoteOpenClawRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun syncSessionStreamStatus(sessionId: String) {
|
||||||
|
val status = streamStatusStore[sessionId]
|
||||||
|
sessions = sessions.map { session ->
|
||||||
|
if (session.id == sessionId) session.copy(streamStatus = status) else session
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 }
|
||||||
@@ -349,6 +362,7 @@ class RemoteOpenClawRepository(
|
|||||||
title = title,
|
title = title,
|
||||||
lastMessage = lastMessage ?: "",
|
lastMessage = lastMessage ?: "",
|
||||||
updatedAt = updatedAt,
|
updatedAt = updatedAt,
|
||||||
|
streamStatus = streamStatusStore[id],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
@@ -187,6 +187,18 @@ fun SessionListScreen(
|
|||||||
if (session.unreadCount > 0) {
|
if (session.unreadCount > 0) {
|
||||||
StatusPill(text = "${session.unreadCount} 未读", highlighted = true)
|
StatusPill(text = "${session.unreadCount} 未读", highlighted = true)
|
||||||
}
|
}
|
||||||
|
session.streamStatus?.let { streamStatus ->
|
||||||
|
StatusPill(
|
||||||
|
text = when (streamStatus) {
|
||||||
|
"reconnecting" -> "重连中"
|
||||||
|
"failed" -> "已断流"
|
||||||
|
"connecting" -> "连接中"
|
||||||
|
"live" -> "在线"
|
||||||
|
else -> streamStatus
|
||||||
|
},
|
||||||
|
highlighted = streamStatus == "live",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = session.id,
|
text = session.id,
|
||||||
|
|||||||
Reference in new issue
Block a user