complicate the threading at receiving messages a bit more

This commit is contained in:
tibbi 2020-11-28 22:47:11 +01:00
parent 64011e1083
commit f66833e9bd
1 changed files with 23 additions and 17 deletions

View File

@ -3,6 +3,8 @@ package com.simplemobiletools.smsmessenger.receivers
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.provider.Telephony import android.provider.Telephony
import com.simplemobiletools.commons.extensions.isNumberBlocked import com.simplemobiletools.commons.extensions.isNumberBlocked
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -21,25 +23,29 @@ class SmsReceiver : BroadcastReceiver() {
val read = 0 val read = 0
val subscriptionId = intent.getIntExtra("subscription", -1) val subscriptionId = intent.getIntExtra("subscription", -1)
messages.forEach { ensureBackgroundThread {
address = it.originatingAddress ?: "" messages.forEach {
subject = it.pseudoSubject address = it.originatingAddress ?: ""
body += it.messageBody subject = it.pseudoSubject
date = Math.min(it.timestampMillis, System.currentTimeMillis()) body += it.messageBody
threadId = context.getThreadId(address) date = Math.min(it.timestampMillis, System.currentTimeMillis())
} threadId = context.getThreadId(address)
if (!context.isNumberBlocked(address)) {
ensureBackgroundThread {
context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
context.conversationsDB.insertOrUpdate(conversation)
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
} }
context.showReceivedMessageNotification(address, body, threadId.toInt(), null) Handler(Looper.getMainLooper()).post {
refreshMessages() if (!context.isNumberBlocked(address)) {
ensureBackgroundThread {
context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
context.conversationsDB.insertOrUpdate(conversation)
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
}
context.showReceivedMessageNotification(address, body, threadId.toInt(), null)
refreshMessages()
}
}
} }
} }
} }