communicate-wear: a decline verdict dismisses only the call it targeted
- Commit
ae9627b644a89880c23fe4aeb95f5a0966b90d64- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 10:51 UTC (5 days ago)
- Parents
a19d15d
applyOpResult cleared _incomingCall on any successful DeclineCall verdict, ignoring which call the op targeted: decline call A, call B arrives and rings, then the phone's success verdict for A's op lands โ B's ringing UI vanished with no user action on B, undeletable and unseen. An unknown/duplicate opId verdict cleared it the same way. Dismissal now resolves against the pre-verdict pending list via incomingCallAfterResult: only a successful DeclineCall verdict matching a pending DeclineCall op whose targetKey equals the shown call's key clears it; failure, unknown and mismatched verdicts leave the current call untouched. The protocol copy is unchanged. New test covers the targeted clear, the B-survives regression and the negative cases. Reply/read ops, thread keying and reconnect honesty were audited and cleared. Verified: :communicate-wear: testDebugUnitTest 11 tests and lint BUILD SUCCESSFUL.
Diff
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.ktindex aad0714ea0..fd294e2b24 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt@@ -112,12 +112,14 @@ class WearCommunicateStore private constructor(private val context: Context) { /** Applies a phone verdict: success drops the op, failure keeps it pending. */ fun applyOpResult(result: WearOpResult) {+ // Resolve the call to dismiss against the pre-verdict pending list:+ // only the DeclineCall op that targeted the shown call clears it.+ _incomingCall.value = incomingCallAfterResult(_incomingCall.value, _pendingOps.value, result) val updated = pendingAfterResult(_pendingOps.value, result) if (updated != _pendingOps.value) { _pendingOps.value = updated persistPending() }- if (result.kind == WearOpKind.DeclineCall && result.success) _incomingCall.value = null } fun queueReply(thread: WearThread, body: String): WearCommOp? {@@ -197,3 +199,21 @@ class WearCommunicateStore private constructor(private val context: Context) { .onFailure { Log.status(TAG, "persist ${file.name} failed: ${it.message}") } } }++/**+ * Incoming call after a phone [result]: only a success verdict for the+ * pending DeclineCall op that targets the currently shown call clears it.+ * A verdict for an earlier call (or an unknown/mismatched op) must not+ * dismiss a newer incoming call that arrived while the verdict was in+ * flight; the pending op โ not the verdict's kind alone โ names the call.+ */+internal fun incomingCallAfterResult(+ current: WearIncomingCall?,+ pending: List<WearCommOp>,+ result: WearOpResult,+): WearIncomingCall? {+ if (current == null || !result.success || result.kind != WearOpKind.DeclineCall) return current+ val op = pending.firstOrNull { it.opId == result.opId } ?: return current+ if (op.kind != WearOpKind.DeclineCall) return current+ return if (op.targetKey == current.callKey) null else current+}
communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt
diff --git a/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.ktnew file mode 100644index 0000000000..c913be9103--- /dev/null+++ b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt@@ -0,0 +1,42 @@+package com.vayunmathur.communicate.wear.data++import com.vayunmathur.communicate.wear.domain.WearCommOp+import com.vayunmathur.communicate.wear.domain.WearIncomingCall+import com.vayunmathur.communicate.wear.domain.WearOpKind+import com.vayunmathur.communicate.wear.domain.WearOpResult+import kotlin.test.Test+import kotlin.test.assertEquals++class WearIncomingCallAfterResultTest {++ @Test+ fun declineVerdictClearsOnlyTheCallItTargeted() {+ val callA = WearIncomingCall(callKey = "callA", displayName = "Alice")+ val callB = WearIncomingCall(callKey = "callB", displayName = "Ben")+ val declineA = WearCommOp(+ opId = "opA", kind = WearOpKind.DeclineCall, targetKey = "callA",+ )+ val successA = WearOpResult("opA", WearOpKind.DeclineCall, success = true)+ // The targeted call is dismissed by its own verdict.+ assertEquals(null, incomingCallAfterResult(callA, listOf(declineA), successA))+ // Regression: call B arrived while opA's verdict was in flight; the+ // verdict for A must not dismiss B's ringing UI.+ assertEquals(callB, incomingCallAfterResult(callB, listOf(declineA), successA))+ // A failed verdict, an unknown op, and a mismatched pending op also+ // leave the current call untouched.+ assertEquals(+ callA,+ incomingCallAfterResult(+ callA, listOf(declineA),+ WearOpResult("opA", WearOpKind.DeclineCall, success = false),+ ),+ )+ assertEquals(callA, incomingCallAfterResult(callA, emptyList(), successA))+ assertEquals(+ callA,+ incomingCallAfterResult(+ callA, listOf(declineA.copy(kind = WearOpKind.MarkRead)), successA,+ ),+ )+ }+}