diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index d5a2fc17..9971c827 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -180,7 +180,7 @@ fun Context.getMMSSender(msgId: Int): String { return "" } -fun Context.getConversations(): ArrayList { +fun Context.getConversations(threadId: Long? = null): ArrayList { val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true") val projection = arrayOf( Threads._ID, @@ -190,8 +190,13 @@ fun Context.getConversations(): ArrayList { Threads.RECIPIENT_IDS ) - val selection = "${Threads.MESSAGE_COUNT} > ?" - val selectionArgs = arrayOf("0") + var selection = "${Threads.MESSAGE_COUNT} > ?" + var selectionArgs = arrayOf("0") + if (threadId != null) { + selection += " AND ${Threads._ID} = ?" + selectionArgs = arrayOf("0", threadId.toString()) + } + val sortOrder = "${Threads.DATE} DESC" val conversations = ArrayList() diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsReceiver.kt index da7f70be..9cdb9a1a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsReceiver.kt @@ -6,6 +6,8 @@ import com.bumptech.glide.Glide import com.simplemobiletools.commons.extensions.isNumberBlocked import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.smsmessenger.R +import com.simplemobiletools.smsmessenger.extensions.conversationsDB +import com.simplemobiletools.smsmessenger.extensions.getConversations import com.simplemobiletools.smsmessenger.extensions.getLatestMMS import com.simplemobiletools.smsmessenger.extensions.showReceivedMessageNotification @@ -32,6 +34,8 @@ class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() { } context.showReceivedMessageNotification(address, mms.body, mms.thread, glideBitmap, mms.id, true) + val conversation = context.getConversations(mms.thread.toLong()).firstOrNull() ?: return@ensureBackgroundThread + context.conversationsDB.insertOrUpdate(conversation) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt index 4e79e291..a57e042a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt @@ -5,9 +5,8 @@ import android.content.Context import android.content.Intent import android.provider.Telephony import com.simplemobiletools.commons.extensions.isNumberBlocked -import com.simplemobiletools.smsmessenger.extensions.getThreadId -import com.simplemobiletools.smsmessenger.extensions.insertNewSMS -import com.simplemobiletools.smsmessenger.extensions.showReceivedMessageNotification +import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.smsmessenger.extensions.* import com.simplemobiletools.smsmessenger.helpers.refreshMessages class SmsReceiver : BroadcastReceiver() { @@ -34,6 +33,11 @@ class SmsReceiver : BroadcastReceiver() { val messageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId) context.showReceivedMessageNotification(address, body, threadId.toInt(), null, messageId, false) refreshMessages() + + ensureBackgroundThread { + val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread + context.conversationsDB.insertOrUpdate(conversation) + } } } }