From bfd5450435d2aebee425516da16e4d1965205344 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Apr 2024 10:57:32 +0000 Subject: [PATCH] Add bulk version of updateLastConversationMessage() In situations where we want to update multiple conversations (e.g. during import), we can make it faster by only calling contentResolver.delete() once. (We still make separate calls to getConversations() because it doesn't support multiple IDs, and likewise insertOrUpdateConversation() doesn't support bulk insert.) --- .../org/fossify/messages/extensions/Context.kt | 12 +++++++++--- 1 file changed, 9 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 26c6d226..f4fff271 100644 --- a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt @@ -1114,7 +1114,11 @@ fun Context.deleteSmsDraft(threadId: Long) { } fun Context.updateLastConversationMessage(threadId: Long) { - // update the date and the snippet of the thread, by triggering the + updateLastConversationMessage(setOf(threadId)) +} + +fun Context.updateLastConversationMessage(threadIds: Iterable) { + // update the date and the snippet of the threads, 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 @@ -1122,8 +1126,10 @@ fun Context.updateLastConversationMessage(threadId: Long) { "1 = 0" // always-false condition, because we don't actually want to delete any messages try { contentResolver.delete(uri, selection, null) - val newConversation = getConversations(threadId)[0] - insertOrUpdateConversation(newConversation) + for (threadId in threadIds) { + val newConversation = getConversations(threadId)[0] + insertOrUpdateConversation(newConversation) + } } catch (e: Exception) { } }