communicate: fix repository extension imports, extract read effects, pin hmac 0.13
- Commit
04392bba83f7f136d79e7ce640325f4877b8c8b6- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-19 16:50 UTC (2 months ago)
- Parents
45181ef
Diff
communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.ktindex 535f8c3d92..226493215e 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt@@ -11,6 +11,7 @@ import android.telecom.VideoProfile import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.CommunicateRepository+import com.vayunmathur.communicate.data.findContactName import com.vayunmathur.library.util.ensureNotificationChannel /** In-call bridge for carrier/SIM calls that lets Communicate expose notification controls. */
communicate/src/main/java/com/vayunmathur/communicate/ui/CallLogsScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/CallLogsScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/CallLogsScreen.ktindex fe92c4c686..acf4d3f5ea 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/CallLogsScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/CallLogsScreen.kt@@ -40,6 +40,7 @@ import com.vayunmathur.communicate.data.CommunicateCallType import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.deleteCallLog import com.vayunmathur.communicate.data.loadCallLogsMerged+import com.vayunmathur.communicate.data.placeCall import com.vayunmathur.communicate.domain.callDurationParts import com.vayunmathur.library.util.AppMessages import kotlinx.coroutines.Dispatchers
communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationMessageBubble.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationMessageBubble.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationMessageBubble.ktindex ab03c727d0..702f8b6e1f 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationMessageBubble.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationMessageBubble.kt@@ -23,6 +23,7 @@ import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.MessageStatus import com.vayunmathur.communicate.data.SmsMessage+import com.vayunmathur.communicate.data.findContactName import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text
communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationReadEffects.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationReadEffects.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationReadEffects.ktnew file mode 100644index 0000000000..780f40ff47--- /dev/null+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationReadEffects.kt@@ -0,0 +1,98 @@+package com.vayunmathur.communicate.ui++import android.content.Context+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 com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.CommunicateRepository+import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceParser+import com.vayunmathur.communicate.data.markSignalRead+import com.vayunmathur.communicate.data.markSimThreadRead+import com.vayunmathur.communicate.data.markWhatsAppRead+import com.vayunmathur.communicate.data.updateGoogleVoiceThread++/**+ * Per-line side effects for an open conversation: mark-read dispatch plus the+ * foreground polling loops for lines with no realtime channel yet.+ *+ * Extracted from [ConversationScreen] to keep that file under the 350-line+ * `ui` package limit. Read receipts mirror across all four lines; polling+ * ticks bump [onRefreshTick] so the message list re-fetches.+ */+@Composable+fun ConversationReadEffects(+ context: Context,+ line: CommunicateLine,+ threadId: Long,+ remoteId: String?,+ address: String,+ onRefreshTick: () -> Unit,+) {+ // 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).+ LaunchedEffect(threadId, line) {+ if (line == CommunicateLine.Sim) {+ CommunicateRepository.markSimThreadRead(context, threadId)+ }+ }+ // Opening a Google Voice thread marks it read server-side via batchupdateattributes.+ LaunchedEffect(remoteId, line) {+ if (line == CommunicateLine.GoogleVoice && remoteId != null) {+ CommunicateRepository.updateGoogleVoiceThread(+ context, remoteId, GoogleVoiceParser.ThreadAction.MarkRead,+ )+ }+ }+ // Foreground polling for the open GV thread (no realtime channel yet).+ LaunchedEffect(remoteId, line) {+ if (line == CommunicateLine.GoogleVoice && remoteId != null) {+ while (true) {+ kotlinx.coroutines.delay(10_000)+ onRefreshTick()+ }+ }+ }+ // WhatsApp messages land in local Room via the socket→event-processor; poll the cache so inbound+ // (and our own outgoing echo) appear live while the conversation is open. Cheap local reads.+ LaunchedEffect(line) {+ if (line == CommunicateLine.WhatsApp) {+ while (true) {+ kotlinx.coroutines.delay(2_000)+ onRefreshTick()+ }+ }+ }+ // Send WhatsApp read receipts (and clear the unread badge) for the open conversation. Re-runs on+ // each poll tick; the repository guards against re-sending for an already-read message.+ var waLastReadId by remember(remoteId, address) { mutableStateOf<String?>(null) }+ LaunchedEffect(line, remoteId, address) {+ if (line == CommunicateLine.WhatsApp) {+ waLastReadId = CommunicateRepository.markWhatsAppRead(context, remoteId, address, waLastReadId)+ }+ }+ // Signal messages land in local Room via the socket→event-processor; poll so inbound+ // (and our own outgoing echo) appear live while the conversation is open.+ LaunchedEffect(line) {+ if (line == CommunicateLine.Signal) {+ while (true) {+ kotlinx.coroutines.delay(2_000)+ onRefreshTick()+ }+ }+ }+ // Send Signal read receipts for the open conversation (mirrors WhatsApp).+ var sigLastReadId by remember(remoteId, address) { mutableStateOf<String?>(null) }+ LaunchedEffect(line, remoteId, address) {+ if (line == CommunicateLine.Signal) {+ sigLastReadId = try {+ CommunicateRepository.markSignalRead(context, remoteId, address, sigLastReadId)+ } catch (_: Throwable) {+ sigLastReadId+ }+ }+ }+}
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 223d85d8e1..a554bf3d54 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationScreen.kt@@ -25,9 +25,14 @@ import com.vayunmathur.communicate.data.SmsMessage import com.vayunmathur.communicate.data.SmsThread import com.vayunmathur.communicate.data.canSendPoll import com.vayunmathur.communicate.data.canShareContact+import com.vayunmathur.communicate.data.findContactName+import com.vayunmathur.communicate.data.isUnknownContact+import com.vayunmathur.communicate.data.loadSmsMessagesMerged+import com.vayunmathur.communicate.data.acceptSignalIdentity+import com.vayunmathur.communicate.data.sendMessage import com.vayunmathur.communicate.data.sendPoll import com.vayunmathur.communicate.data.shareContact-import com.vayunmathur.communicate.data.updateGoogleVoiceThread+import com.vayunmathur.communicate.data.signalPendingIdentityChange import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.util.AppMessages@@ -140,69 +145,16 @@ 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) {- CommunicateRepository.updateGoogleVoiceThread(- context, remoteId, com.vayunmathur.communicate.data.googlevoice.GoogleVoiceParser.ThreadAction.MarkRead,- )- }- }- // Foreground polling for the open GV thread (no realtime channel yet).- androidx.compose.runtime.LaunchedEffect(remoteId, line) {- if (line == CommunicateLine.GoogleVoice && remoteId != null) {- while (true) {- kotlinx.coroutines.delay(10_000)- refresh++- }- }- }- // WhatsApp messages land in local Room via the socket→event-processor; poll the cache so inbound- // (and our own outgoing echo) appear live while the conversation is open. Cheap local reads.- androidx.compose.runtime.LaunchedEffect(line) {- if (line == CommunicateLine.WhatsApp) {- while (true) {- kotlinx.coroutines.delay(2_000)- refresh++- }- }- }- // Send WhatsApp read receipts (and clear the unread badge) for the open conversation. Re-runs on- // each poll tick; the repository guards against re-sending for an already-read message.- var waLastReadId by remember(remoteId, address) { mutableStateOf<String?>(null) }- androidx.compose.runtime.LaunchedEffect(line, remoteId, refresh) {- if (line == CommunicateLine.WhatsApp) {- waLastReadId = CommunicateRepository.markWhatsAppRead(context, remoteId, address, waLastReadId)- }- }- // Signal messages land in local Room via the socket→event-processor; poll so inbound- // (and our own outgoing echo) appear live while the conversation is open.- androidx.compose.runtime.LaunchedEffect(line) {- if (line == CommunicateLine.Signal) {- while (true) {- kotlinx.coroutines.delay(2_000)- refresh++- }- }- }- // Send Signal read receipts for the open conversation (mirrors WhatsApp).- var sigLastReadId by remember(remoteId, address) { mutableStateOf<String?>(null) }- androidx.compose.runtime.LaunchedEffect(line, remoteId, refresh) {- if (line == CommunicateLine.Signal) {- sigLastReadId = try {- CommunicateRepository.markSignalRead(context, remoteId, address, sigLastReadId)- } catch (_: Throwable) {- sigLastReadId- }- }- }+ // Per-line mark-read dispatch + foreground polling (no realtime channel+ // yet on GV/WhatsApp/Signal). Extracted to keep this file under the limit.+ ConversationReadEffects(+ context = context,+ line = line,+ threadId = threadId,+ remoteId = remoteId,+ address = address,+ onRefreshTick = { refresh++ },+ ) AppScaffold( title = {
communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationTopBar.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationTopBar.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationTopBar.ktindex cc7f417eb2..9ebab323a4 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationTopBar.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ConversationTopBar.kt@@ -20,7 +20,11 @@ import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.SmsThread+import com.vayunmathur.communicate.data.canPlaceCall+import com.vayunmathur.communicate.data.canPlaceGroupCall+import com.vayunmathur.communicate.data.canPlaceVideoCall import com.vayunmathur.communicate.data.deleteConversation+import com.vayunmathur.communicate.data.placeCallForLine import com.vayunmathur.communicate.data.updateGoogleVoiceThread import com.vayunmathur.library.ui.IconArchive import com.vayunmathur.library.ui.IconButton
communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.ktindex 3beb5f634f..a0a378a746 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt@@ -41,6 +41,8 @@ import com.vayunmathur.communicate.data.CommunicateContact import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.LineChoice import com.vayunmathur.communicate.data.T9+import com.vayunmathur.communicate.data.loadContacts+import com.vayunmathur.communicate.data.placeCall import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceSession import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager import com.vayunmathur.communicate.telephony.GoogleVoiceTelecom
communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.ktindex 727251f112..20b0233c1b 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt@@ -21,8 +21,14 @@ import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.SmsThread+import com.vayunmathur.communicate.data.createSignalGroup+import com.vayunmathur.communicate.data.createWhatsAppGroup import com.vayunmathur.communicate.data.deleteConversation+import com.vayunmathur.communicate.data.getOrCreateSmsGroupThreadId+import com.vayunmathur.communicate.data.getOrCreateSmsThreadId import com.vayunmathur.communicate.data.isWhatsAppConnected+import com.vayunmathur.communicate.data.loadSmsThreadsMerged+import com.vayunmathur.communicate.data.stableThreadId import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.FloatingActionButton import com.vayunmathur.library.ui.HorizontalDivider
communicate/src/main/java/com/vayunmathur/communicate/ui/NewMessagePicker.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/NewMessagePicker.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/NewMessagePicker.ktindex 41a7297387..f7cfc33fff 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/NewMessagePicker.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/NewMessagePicker.kt@@ -34,6 +34,7 @@ import com.vayunmathur.communicate.data.CommunicateContact import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.LineChoice+import com.vayunmathur.communicate.data.loadContacts import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Checkbox import com.vayunmathur.library.ui.FilterChip
communicate/src/main/rust/Cargo.toml
diff --git a/communicate/src/main/rust/Cargo.toml b/communicate/src/main/rust/Cargo.tomlindex f8dbc50cb5..64ee442197 100644--- a/communicate/src/main/rust/Cargo.toml+++ b/communicate/src/main/rust/Cargo.toml@@ -13,7 +13,10 @@ crate-type = ["cdylib", "rlib"] curve25519-dalek.workspace = true x25519-dalek.workspace = true sha2.workspace = true-hmac.workspace = true+# hmac 0.13 (digest 0.11 stack) to match the workspace sha2 0.11 pin: Hmac<Sha256>+# mixes both crates' traits, so they must share one digest major. The workspace+# hmac stays 0.12.1 (digest 0.10) for hkdf/rfc6979; only this crate overrides.+hmac = "0.13" aes.workspace = true subtle.workspace = true rand_core.workspace = true
communicate/src/main/rust/src/crypto.rs
diff --git a/communicate/src/main/rust/src/crypto.rs b/communicate/src/main/rust/src/crypto.rsindex a95b923504..c3305690a5 100644--- a/communicate/src/main/rust/src/crypto.rs+++ b/communicate/src/main/rust/src/crypto.rs@@ -48,7 +48,11 @@ pub type Result<T> = core::result::Result<T, CryptoError>; // --------------------------------------------------------------------------- pub fn hmac_sha256(key: &[u8], data: &[u8]) -> [u8; 32] {- let mut mac = <Hmac<Sha256> as Mac>::new_from_slice(key).expect("hmac accepts any key length");+ // Fully qualified: hmac 0.13 re-exports digest 0.11's KeyInit (matching the+ // workspace sha2 0.11 pin). The bare `KeyInit` name resolves to aes's+ // cipher-0.4 copy — a different trait version that Hmac<Sha256> cannot satisfy.+ let mut mac =+ <Hmac<Sha256> as hmac::KeyInit>::new_from_slice(key).expect("hmac accepts any key length"); mac.update(data); mac.finalize().into_bytes().into() }@@ -65,7 +69,7 @@ pub fn hkdf(ikm: &[u8], salt: &[u8], info: &[u8], out_len: usize) -> Vec<u8> { let mut counter: u8 = 1; while out.len() < out_len { let mut mac =- <Hmac<Sha256> as Mac>::new_from_slice(&prk).expect("hmac accepts any key length");+ <Hmac<Sha256> as hmac::KeyInit>::new_from_slice(&prk).expect("hmac accepts any key length"); mac.update(&t); mac.update(info); mac.update(&[counter]);