Modern Apps git

← Modern-Apps.git

communicate: mark SIM threads read when opened (#562)

Commit
9c52e6adc05fcfcca971ac486f643d0abb7501d2
Author
vayun-mathur <[email protected]>
When
2026-08-22 03:35 UTC (3 months ago)
Parents
f43f56f

Diff

communicate/src/main/java/com/vayunmathur/communicate/data/CommunicateRepository.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/CommunicateRepository.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/CommunicateRepository.ktindex 3af0520aaf..472e613761 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/CommunicateRepository.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/CommunicateRepository.kt@@ -176,6 +176,29 @@ object CommunicateRepository {         }.sortedByDescending { it.timestampMillis }     } +    /**+     * Clear the unread flags on a SIM thread's provider rows. SIM [SmsThread.unreadCount] is+     * recomputed from the provider on every load, so a row left at `read = 0` — typically imported+     * from a previously installed SMS app — keeps the badge forever unless something writes it+     * back (#562). Only the default SMS app may write these columns.+     */+    suspend fun markSimThreadRead(context: Context, threadId: Long): Boolean = withContext(Dispatchers.IO) {+        val values = android.content.ContentValues().apply {+            put(Telephony.Sms.READ, 1)+            put(Telephony.Sms.SEEN, 1)+        }+        // SMS and MMS are separate tables sharing the thread id; an unread thread may be either.+        listOf(Telephony.Sms.CONTENT_URI, Telephony.Mms.CONTENT_URI).sumOf { uri ->+            runCatching {+                context.contentResolver.update(+                    uri, values,+                    "${Telephony.Sms.THREAD_ID} = ? AND ${Telephony.Sms.READ} = 0",+                    arrayOf(threadId.toString()),+                )+            }.getOrDefault(0)+        } > 0+    }+     /**      * Map each provider thread id to its recipient addresses via `mms-sms/conversations` +      * `mms-sms/canonical-addresses`. Threads with >1 recipient are group threads. Empty on any
communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.ktindex d7b00e89cf..a874daca6c 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt@@ -147,6 +147,13 @@ fun ConversationScreen(         }     } +    // Opening a SIM thread clears the provider's unread flags. Nothing else writes them back, and+    // the badge is recomputed from the provider, so imported rows would stay unread forever (#562).+    androidx.compose.runtime.LaunchedEffect(threadId, line) {+        if (line == CommunicateLine.Sim) {+            CommunicateRepository.markSimThreadRead(context, threadId)+        }+    }     // Opening a Google Voice thread marks it read server-side via batchupdateattributes.     androidx.compose.runtime.LaunchedEffect(remoteId, line) {         if (line == CommunicateLine.GoogleVoice && remoteId != null) {