Modern Apps git

← Modern-Apps.git

communicate: add Delete thread after Open on phone on watch

Commit
7fb8023f129aa857ac811cd3ce91b82cbed1468a
Author
Vayun Mathur <[email protected]>
When
2026-12-06 04:27 UTC (5 hours ago)
Parents
f8f4662
The watch thread screen had Reply/Mark read, then Open on phone, and no delete although the phone deletes whole conversations. A new WearOpKind DeleteThread rides the existing pending-op channel with a phone verdict; the phone handler builds the thread from the op and calls CommunicateRepository.deleteConversation. The detail now orders Reply/Mark read first (with chat/mark-read icons tinted to the content color), then Open on phone, then the red Delete thread button directly after it with an inline confirmation. Op dispatch tests cover the new kind.

Verified: :communicate:lint, :communicate:lintVitalRelease, :communicate:testDevUnitTest green; wear metadata regenerated.

Diff

communicate/AGENTS.md
diff --git a/communicate/AGENTS.md b/communicate/AGENTS.mdindex 1f7aac729d..c49b08934c 100644--- a/communicate/AGENTS.md+++ b/communicate/AGENTS.md@@ -39,7 +39,7 @@ its messages over the Watch conduit. ## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol`; this module's golden-JSON test pins the shared code's wire format. - Snapshot + watch-state sync: conduit data items (`/communicate/snapshot` phone -> watch, `/communicate/watch-state` watch -> phone)-- Thread pages, new-message/incoming-call alerts, and watch ops with phone verdicts: conduit messages (see the protocol file for paths and caps)+- Thread pages, new-message/incoming-call alerts, and watch ops with phone verdicts (quick reply, mark-read, voicemail-read, decline-call, delete-thread): conduit messages (see the protocol file for paths and caps) - **Transport: Watch conduit client** — phone side `data/WearCommunicateSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `communicate`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; snapshots republish on conduit `Connected`. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device. The watch keeps ops pending and resends on reconnect. - **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearCommunicateSync.syncNow()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration. 
communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateStore.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateStore.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateStore.ktindex 6ab895fd59..70a602bd8b 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateStore.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateStore.kt@@ -153,6 +153,20 @@ class WearCommunicateStore private constructor(private val context: Context) {         ),     ) +    fun queueDeleteThread(thread: WearThread): WearCommOp = queue(+        WearCommOp(+            opId = UUID.randomUUID().toString(),+            kind = WearOpKind.DeleteThread,+            threadKey = thread.key,+            line = thread.line,+            threadId = thread.threadId,+            remoteId = thread.remoteId,+            address = thread.address,+            subscriptionId = thread.subscriptionId,+            participants = thread.participants,+        ),+    )+     fun queueMarkVoicemailRead(voicemail: WearVoicemail): WearCommOp = queue(         WearCommOp(             opId = UUID.randomUUID().toString(),
communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.ktindex a485339c9b..5968fe12fd 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt@@ -50,6 +50,7 @@ internal interface WearOpHandler {     suspend fun markRead(op: WearCommOp): Boolean     suspend fun markVoicemailRead(op: WearCommOp): Boolean     suspend fun declineCall(op: WearCommOp): Boolean+    suspend fun deleteThread(op: WearCommOp): Boolean }  /**@@ -64,6 +65,7 @@ internal suspend fun applyWearCommOp(op: WearCommOp, handler: WearOpHandler): Bo         WearOpKind.MarkRead -> op.threadKey.isNotBlank() && handler.markRead(op)         WearOpKind.MarkVoicemailRead -> op.targetKey.isNotBlank() && handler.markVoicemailRead(op)         WearOpKind.DeclineCall -> op.targetKey.isNotBlank() && handler.declineCall(op)+        WearOpKind.DeleteThread -> op.threadKey.isNotBlank() && handler.deleteThread(op)     }  /**@@ -146,6 +148,24 @@ class WearCommunicateSync private constructor(context: Context) {             return CommunicateRepository.markVoicemailEntryRead(appContext, entry)         } +        override suspend fun deleteThread(op: WearCommOp): Boolean = runCatching {+            val line = CommunicateLine.valueOf(op.line.name)+            CommunicateRepository.deleteConversation(+                appContext,+                SmsThread(+                    threadId = op.threadId,+                    address = op.address,+                    displayName = null,+                    snippet = "",+                    timestampMillis = 0L,+                    unreadCount = 0,+                    line = line,+                    remoteId = op.remoteId,+                    subscriptionId = op.subscriptionId,+                ),+            )+        }.getOrDefault(false)+         override suspend fun declineCall(op: WearCommOp): Boolean {             val call = InAppCallRegistry.state.value             if (call.phase != InAppCallPhase.Incoming) return false
communicate/src/main/java/com/vayunmathur/communicate/ui/WearThreadScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/WearThreadScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/WearThreadScreen.ktindex 92acdc923d..7032b729e2 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/WearThreadScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/WearThreadScreen.kt@@ -1,13 +1,19 @@ package com.vayunmathur.communicate.ui import com.vayunmathur.library.wearlink.wearOpenOnPhoneItem import com.vayunmathur.library.ui.IconMobileArrowRight+import com.vayunmathur.library.ui.IconChat import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconMarkRead import com.vayunmathur.library.wearlink.wearDeleteItem  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope@@ -20,6 +26,7 @@ import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.items import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip+import androidx.wear.compose.material.LocalContentColor import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text@@ -51,7 +58,7 @@ fun WearThreadScreen(     LaunchedEffect(threadKey) {         WearLinkBridge.requestThreadPage(context, threadKey)     }-    WearThreadContent(thread = thread, cache = cache, onLoadOlder = { scope.launch { WearLinkBridge.requestThreadPage(context, threadKey, cache?.oldestTimestampMillis ?: 0L) } }, onReply = onReply, onMarkRead = { if (thread != null) store.queueMarkRead(thread) }, onBack = onBack)+    WearThreadContent(thread = thread, cache = cache, onLoadOlder = { scope.launch { WearLinkBridge.requestThreadPage(context, threadKey, cache?.oldestTimestampMillis ?: 0L) } }, onReply = onReply, onMarkRead = { if (thread != null) store.queueMarkRead(thread) }, onDeleteThread = { if (thread != null) { store.queueDeleteThread(thread); onBack() } }, onBack = onBack) }  /** Stateless thread behind [WearThreadScreen]: thread/cache are parameters for previews. */@@ -62,8 +69,10 @@ internal fun WearThreadContent(     onLoadOlder: () -> Unit,     onReply: (String) -> Unit,     onMarkRead: () -> Unit,+    onDeleteThread: () -> Unit = {},     onBack: () -> Unit, ) {+    var confirmingDelete by remember { mutableStateOf(false) }      val context = LocalContext.current     val scope = rememberCoroutineScope()@@ -143,6 +152,7 @@ internal fun WearThreadContent(                 Chip(                     onClick = { onReply(thread.key) },                     label = { Text(stringResource(R.string.wear_reply), maxLines = 1) },+                    icon = { IconChat(tint = LocalContentColor.current) },                     colors = ChipDefaults.primaryChipColors(),                     modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),                 )@@ -152,12 +162,47 @@ internal fun WearThreadContent(                     Chip(                         onClick = onMarkRead,                         label = { Text(stringResource(R.string.wear_mark_read), maxLines = 1) },+                        icon = { IconMarkRead(tint = LocalContentColor.current) },                         colors = ChipDefaults.secondaryChipColors(),                         modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),                     )                 }             }         }-        wearOpenOnPhoneItem(onClick = { scope.launch { WearLinkBridge.get(context).sendMessage("/communicate/open-on-phone", ByteArray(0)) } }, icon = { IconMobileArrowRight(tint = androidx.compose.ui.graphics.Color.White) })+        wearOpenOnPhoneItem(+            onClick = {+                scope.launch {+                    WearLinkBridge.get(context).sendMessage("/communicate/open-on-phone", ByteArray(0))+                }+            },+            icon = { IconMobileArrowRight(tint = LocalContentColor.current) },+        )+        if (thread != null) {+            if (confirmingDelete) {+                item {+                    Chip(+                        onClick = onDeleteThread,+                        label = { Text("Confirm delete", maxLines = 1) },+                        icon = { IconDelete(tint = LocalContentColor.current) },+                        colors = ChipDefaults.primaryChipColors(),+                        modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+                    )+                }+                item {+                    Chip(+                        onClick = { confirmingDelete = false },+                        label = { Text("Cancel", maxLines = 1) },+                        colors = ChipDefaults.secondaryChipColors(),+                        modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+                    )+                }+            } else {+                wearDeleteItem(+                    label = "Delete thread",+                    onClick = { confirmingDelete = true },+                    icon = { IconDelete(tint = LocalContentColor.current) },+                )+            }+        }     } }
communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.ktindex 00b09e47e7..330f055974 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt@@ -36,6 +36,11 @@ class WearCommunicateOpTest {             calls += "decline:${op.targetKey}"             return true         }++        override suspend fun deleteThread(op: WearCommOp): Boolean {+            calls += "delete:${op.threadKey}"+            return true+        }     }      @Test@@ -101,6 +106,21 @@ class WearCommunicateOpTest {         )     } +    @Test+    fun deleteThreadDispatchesAndNeedsThread() = runBlocking {+        val handler = FakeHandler()+        assertTrue(+            applyWearCommOp(+                WearCommOp(opId = "1", kind = WearOpKind.DeleteThread, threadKey = "Sim:3"),+                handler,+            ),+        )+        assertFalse(+            applyWearCommOp(WearCommOp(opId = "2", kind = WearOpKind.DeleteThread), handler),+        )+        assertEquals(listOf("delete:Sim:3"), handler.calls)+    }+     @Test     fun handlerFailurePropagatesAsFailure() = runBlocking {         val handler = FakeHandler(replyOk = false)
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.ktindex d29e67e2d6..052636dcbd 100644--- a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt@@ -233,7 +233,7 @@ data class WearIncomingCall(  /** Watch-originated actions the phone executes. Archive/mute are absent: the phone UI offers neither. */ @Serializable-enum class WearOpKind { QuickReply, MarkRead, MarkVoicemailRead, DeclineCall }+enum class WearOpKind { QuickReply, MarkRead, MarkVoicemailRead, DeclineCall, DeleteThread }  /** One watch-originated action ([WearCommunicateProtocol.OP_PATH]). */ @Serializable
metadata_data/photos/communicate/wear/2.png
diff --git a/metadata_data/photos/communicate/wear/2.png b/metadata_data/photos/communicate/wear/2.pngindex 42cd8d4735..179eb4fed8 100644Binary files a/metadata_data/photos/communicate/wear/2.png and b/metadata_data/photos/communicate/wear/2.png differ