properly add new messages into the local database on receiving
This commit is contained in:
parent
661798cff4
commit
0db8b202c7
|
@ -180,7 +180,7 @@ fun Context.getMMSSender(msgId: Int): String {
|
|||
return ""
|
||||
}
|
||||
|
||||
fun Context.getConversations(): ArrayList<Conversation> {
|
||||
fun Context.getConversations(threadId: Long? = null): ArrayList<Conversation> {
|
||||
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
|
||||
val projection = arrayOf(
|
||||
Threads._ID,
|
||||
|
@ -190,8 +190,13 @@ fun Context.getConversations(): ArrayList<Conversation> {
|
|||
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<Conversation>()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue