From e1078d4379ca998798aa8eef8f71ae18b97bc380 Mon Sep 17 00:00:00 2001 From: Mysochenko Yuriy Date: Fri, 27 May 2022 18:12:33 +0300 Subject: [PATCH] update to the latest commons version --- app/build.gradle | 2 +- .../smsmessenger/receivers/SmsReceiver.kt | 69 +++++++++++-------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c1f2a55f..b00bcac9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:59f709a2a8' + implementation 'com.github.SimpleMobileTools:Simple-Commons:10c8ac2f1e' implementation 'org.greenrobot:eventbus:3.3.1' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'com.github.tibbi:android-smsmms:fe58a74d59' 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 41db8a6e..b71ee252 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsReceiver.kt @@ -45,41 +45,52 @@ class SmsReceiver : BroadcastReceiver() { threadId = context.getThreadId(address) } - val bitmap = getPhotoForNotification(address, context) - - Handler(Looper.getMainLooper()).post { - val privateCursor = context.getMyContactsCursor(false, true) + if (context.baseConfig.blockUnknownNumbers) { val simpleContactsHelper = SimpleContactsHelper(context) - val isBlocked = context.baseConfig.blockUnknownNumbers && !simpleContactsHelper.exists(address) - if (!isBlocked && !context.isNumberBlocked(address)) { - ensureBackgroundThread { - val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId) + simpleContactsHelper.exists(address) { exists -> + if (exists) { + handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status) + } + } + } else { + handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status) + } + } + } - val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread - try { - context.conversationsDB.insertOrUpdate(conversation) - } catch (ignored: Exception) { - } + private fun handleMessage(context: Context, address: String, subject: String, body: String, date: Long, read: Int, + threadId: Long, type: Int, subscriptionId: Int, status: Int) { + 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 { - 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() + val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread + try { + context.conversationsDB.insertOrUpdate(conversation) + } catch (ignored: Exception) { } - 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) } } }