Preserve hide notice re-entry fixes before renewed UI acceptance

This commit is contained in:
2026-10-18 23:29:59 +01:00
parent 0b160ac1fc
commit 1ebf0f46dc
5 changed files with 42 additions and 17 deletions
@@ -1108,6 +1108,8 @@ class AppViewModel(
fun consumeChatRemovalNotice(noticeId: Long) = chatStore.consumeRemovalNotice(noticeId) fun consumeChatRemovalNotice(noticeId: Long) = chatStore.consumeRemovalNotice(noticeId)
fun beginChatRemovalNotice(noticeId: Long) = chatStore.beginRemovalNotice(noticeId)
fun undoRemoveChat(sessionId: String) = chatStore.undoRemove(sessionId) fun undoRemoveChat(sessionId: String) = chatStore.undoRemove(sessionId)
fun loadChatHistory(sessionId: String) { fun loadChatHistory(sessionId: String) {
@@ -110,21 +110,20 @@ internal fun ChatListPane(
val removalNotice = state.removalNotice val removalNotice = state.removalNotice
LaunchedEffect(removalNotice?.id) { LaunchedEffect(removalNotice?.id) {
removalNotice?.let { notice -> removalNotice?.let { notice ->
// A rapid second hide replaces, rather than queues behind, the first // Claim delivery before showing. Completion remains separate so a
// report. Do not consume until showSnackbar finishes: consuming first // cancelled effect cannot make this same notice replay on re-entry.
// changes this effect's key and cancels the snackbar coroutine. if (vm.beginChatRemovalNotice(notice.id)) {
snackbarHostState.currentSnackbarData?.dismiss() // A rapid second hide replaces, rather than queues behind, the first.
if (snackbarHostState.showSnackbar( snackbarHostState.currentSnackbarData?.dismiss()
message = CHAT_REMOVED_MESSAGE, if (snackbarHostState.showSnackbar(
actionLabel = "Undo", message = CHAT_REMOVED_MESSAGE,
duration = SnackbarDuration.Short, actionLabel = "Undo",
) == SnackbarResult.ActionPerformed) { duration = SnackbarDuration.Short,
vm.undoRemoveChat(notice.sessionId) ) == SnackbarResult.ActionPerformed) {
vm.undoRemoveChat(notice.sessionId)
}
vm.consumeChatRemovalNotice(notice.id)
} }
// A completed notice is not replayed after the pane is recreated. If
// another hide replaced it while this coroutine was cancelled, this
// exact-id consume is a no-op and the newer notice remains pending.
vm.consumeChatRemovalNotice(notice.id)
} }
} }
var renaming by remember { mutableStateOf<ChatSession?>(null) } var renaming by remember { mutableStateOf<ChatSession?>(null) }
@@ -260,6 +260,8 @@ data class ChatState(
* hide irreversible, and revisiting the list must not report it again. * hide irreversible, and revisiting the list must not report it again.
*/ */
val removalNotice: ChatRemovalNotice? = null, val removalNotice: ChatRemovalNotice? = null,
/** The notice whose snackbar delivery has already started, if any. */
val removalNoticePresentedId: Long? = null,
/** What the operator has read of the list (see [ChatSeenState]). */ /** What the operator has read of the list (see [ChatSeenState]). */
val seen: ChatSeenState = ChatSeenState(), val seen: ChatSeenState = ChatSeenState(),
/** /**
@@ -562,6 +564,14 @@ class ChatStore(
} }
} }
/** Claims a notice before delivery so a cancelled pane cannot replay it. */
fun beginRemovalNotice(noticeId: Long): Boolean {
val state = _state.value
if (state.removalNotice?.id != noticeId || state.removalNoticePresentedId == noticeId) return false
_state.value = state.copy(removalNoticePresentedId = noticeId)
return true
}
/** Restores [sessionId] only when it is still the current undoable removal. */ /** Restores [sessionId] only when it is still the current undoable removal. */
fun undoRemove(sessionId: String? = null) { fun undoRemove(sessionId: String? = null) {
val id = _state.value.lastRemoved ?: return val id = _state.value.lastRemoved ?: return
@@ -74,4 +74,18 @@ class ChatRemovalNoticeTest {
assertNull(store.value.removalNotice) assertNull(store.value.removalNotice)
assertEquals(listOf("b", "c"), store.value.visibleSessions.map { it.id }) assertEquals(listOf("b", "c"), store.value.visibleSessions.map { it.id })
} }
@Test
fun presentedNoticeDoesNotReplayWhenLeavingAndReenteringBeforeItExpires() {
val store = store()
store.remove("a")
val notice = store.value.removalNotice!!
assertTrue(store.beginRemovalNotice(notice.id))
store.showList()
assertFalse(store.beginRemovalNotice(notice.id))
assertEquals(notice, store.value.removalNotice)
assertEquals(listOf("b", "c"), store.value.visibleSessions.map { it.id })
}
} }
+3 -3
View File
@@ -4,9 +4,9 @@
`android/app/src/main/java/net/awan/pipelines/ui/chat/ChatListPane.kt` now presents a local-hide `android/app/src/main/java/net/awan/pipelines/ui/chat/ChatListPane.kt` now presents a local-hide
notice once with Material's short, finite snackbar duration. The `ChatStore` keeps the one-shot notice once with Material's short, finite snackbar duration. The `ChatStore` keeps the one-shot
notice separate from the undoable local override, and the pane consumes it only after the snackbar notice separate from the undoable local override and records delivery separately from snackbar
finishes so changing the effect key cannot cancel its display. A later hide replaces the pending completion, so leaving and re-entering cannot replay an in-flight notice. A later hide replaces the
notice rather than queueing it. Returning to the list, pending notice rather than queueing it. Returning to the list,
recomposition and a session refresh therefore cannot replay an already-finished notice; Undo still recomposition and a session refresh therefore cannot replay an already-finished notice; Undo still
restores only the current local hide and does not delete server state or history. restores only the current local hide and does not delete server state or history.