From 99cea602c8e7211d8229dcaee3ca765bbd0e7549 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Sat, 23 Mar 2024 14:04:30 +0000 Subject: [PATCH] Fix deletion of random SMS when trying to update threads Commit 44c540b9 (Fixed updating last message after deleting (#167), 2021-09-04) introduced a hack to update the conversation snippet, however there is a bug in that code: it tries to delete by thread ID, but the condition is applied to the SMS table, not to the threads table.[1] So instead of deleting the thread with that ID, it deletes whichever SMS happens to have that ID. The fix is to change the condition to an always-false condition, so that no messages will be deleted. The threads will still get updated.[2] Fixes #148. [1] https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1405 [2] https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1409 --- .../kotlin/org/fossify/messages/extensions/Context.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt index 8e18d8d2..5aa24e30 100644 --- a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt @@ -990,11 +990,13 @@ fun Context.deleteSmsDraft(threadId: Long) { } fun Context.updateLastConversationMessage(threadId: Long) { + // update the date and the snippet of the thread, by triggering the + // following Android code (which runs even if no messages are deleted): + // https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1409 val uri = Threads.CONTENT_URI - val selection = "${Threads._ID} = ?" - val selectionArgs = arrayOf(threadId.toString()) + val selection = "1 = 0" // always-false condition, because we don't actually want to delete any messages try { - contentResolver.delete(uri, selection, selectionArgs) + contentResolver.delete(uri, selection, null) val newConversation = getConversations(threadId)[0] insertOrUpdateConversation(newConversation) } catch (e: Exception) {