mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-25 16:07:45 +01:00
Merge pull request #348 from sdex/block_unknown_numbers
Check if the number exists in the contacts and the private contacts
This commit is contained in:
commit
cf3f212398
@ -62,7 +62,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:59f709a2a8'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:10c8ac2f1e'
|
||||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||||
implementation 'com.github.tibbi:android-smsmms:fe58a74d59'
|
implementation 'com.github.tibbi:android-smsmms:fe58a74d59'
|
||||||
|
@ -35,6 +35,7 @@ class SmsReceiver : BroadcastReceiver() {
|
|||||||
val read = 0
|
val read = 0
|
||||||
val subscriptionId = intent.getIntExtra("subscription", -1)
|
val subscriptionId = intent.getIntExtra("subscription", -1)
|
||||||
|
|
||||||
|
val privateCursor = context.getMyContactsCursor(false, true)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
messages.forEach {
|
messages.forEach {
|
||||||
address = it.originatingAddress ?: ""
|
address = it.originatingAddress ?: ""
|
||||||
@ -45,41 +46,53 @@ class SmsReceiver : BroadcastReceiver() {
|
|||||||
threadId = context.getThreadId(address)
|
threadId = context.getThreadId(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
val bitmap = getPhotoForNotification(address, context)
|
if (context.baseConfig.blockUnknownNumbers) {
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
val privateCursor = context.getMyContactsCursor(false, true)
|
|
||||||
val simpleContactsHelper = SimpleContactsHelper(context)
|
val simpleContactsHelper = SimpleContactsHelper(context)
|
||||||
val isBlocked = context.baseConfig.blockUnknownNumbers && !simpleContactsHelper.exists(address)
|
simpleContactsHelper.exists(address, privateCursor) { exists ->
|
||||||
if (!isBlocked && !context.isNumberBlocked(address)) {
|
if (exists) {
|
||||||
ensureBackgroundThread {
|
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status)
|
||||||
val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
|
private fun handleMessage(
|
||||||
try {
|
context: Context, address: String, subject: String, body: String, date: Long, read: Int, threadId: Long, type: Int, subscriptionId: Int, status: Int
|
||||||
context.conversationsDB.insertOrUpdate(conversation)
|
) {
|
||||||
} catch (ignored: Exception) {
|
val bitmap = getPhotoForNotification(address, context)
|
||||||
}
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
if (!context.isNumberBlocked(address)) {
|
||||||
|
val privateCursor = context.getMyContactsCursor(false, true)
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
||||||
|
|
||||||
try {
|
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
|
||||||
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
try {
|
||||||
} catch (ignored: Exception) {
|
context.conversationsDB.insertOrUpdate(conversation)
|
||||||
}
|
} catch (ignored: Exception) {
|
||||||
|
|
||||||
val senderName = context.getNameFromAddress(address, privateCursor)
|
|
||||||
val phoneNumber = PhoneNumber(address, 0, "", address)
|
|
||||||
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
|
|
||||||
val participants = arrayListOf(participant)
|
|
||||||
val messageDate = (date / 1000).toInt()
|
|
||||||
|
|
||||||
val message =
|
|
||||||
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
|
|
||||||
context.messagesDB.insertOrUpdate(message)
|
|
||||||
refreshMessages()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.showReceivedMessageNotification(address, body, threadId, bitmap)
|
try {
|
||||||
|
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
val senderName = context.getNameFromAddress(address, privateCursor)
|
||||||
|
val phoneNumber = PhoneNumber(address, 0, "", address)
|
||||||
|
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
|
||||||
|
val participants = arrayListOf(participant)
|
||||||
|
val messageDate = (date / 1000).toInt()
|
||||||
|
|
||||||
|
val message =
|
||||||
|
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
|
||||||
|
context.messagesDB.insertOrUpdate(message)
|
||||||
|
refreshMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.showReceivedMessageNotification(address, body, threadId, bitmap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user