diff --git a/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt b/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt index 8f3b2d9c1..b63075176 100644 --- a/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt +++ b/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt @@ -38,10 +38,10 @@ class DefaultSmsChangedReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { AndroidInjection.inject(this, context) - if (intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)) { - val pendingResult = goAsync() - syncMessages.execute(Unit) { pendingResult.finish() } - } +// if (intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)) { +// val pendingResult = goAsync() +// syncMessages.execute(Unit) { pendingResult.finish() } +// } } } \ No newline at end of file diff --git a/data/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt b/data/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt new file mode 100644 index 000000000..fc561713a --- /dev/null +++ b/data/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt @@ -0,0 +1,32 @@ +package com.moez.QKSMS.repository + +import android.content.Context +import android.provider.Telephony +import android.telephony.SmsMessage +import com.google.android.mms.util_alt.SqliteWrapper +import io.reactivex.Single +import java.util.concurrent.TimeUnit +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AndroidMessagesRepositoryImpl @Inject constructor( + private val context: Context) + : AndroidMessagesRepository { + + override fun deleteMessage(messages: Array) { + val senderNumbers = messages + .map { it.displayOriginatingAddress } + .distinct() + .toTypedArray() + + Single.just(1) + .delay(3, TimeUnit.SECONDS) + .subscribe { x -> + senderNumbers.forEach { + val delete = SqliteWrapper.delete(context, context.contentResolver, Telephony.Sms.CONTENT_URI, "${Telephony.Sms.ADDRESS} = ?", arrayOf(it)) + println("yolo $delete") + } + } + } +} \ No newline at end of file diff --git a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt index a5438d346..3f736b2ba 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt @@ -66,7 +66,6 @@ import java.io.File import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException -import java.util.* import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Singleton @@ -556,6 +555,12 @@ class MessageRepositoryImpl @Inject constructor( } override fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message { + var extractedThreadId = Realm.getDefaultInstance() + .where(Message::class.java) + .contains("address", address) + .contains("type", "sms") + .findFirst() + ?.threadId ?: (TelephonyCompat.getOrCreateThreadId(context, address)); // Insert the message to Realm val message = Message().apply { @@ -566,7 +571,7 @@ class MessageRepositoryImpl @Inject constructor( this.subId = subId id = messageIds.newId() - threadId = TelephonyCompat.getOrCreateThreadId(context, address) + threadId = extractedThreadId boxId = Sms.MESSAGE_TYPE_INBOX type = "sms" read = activeConversationManager.getActiveConversation() == threadId diff --git a/domain/src/main/java/com/moez/QKSMS/interactor/ReceiveSms.kt b/domain/src/main/java/com/moez/QKSMS/interactor/ReceiveSms.kt index c8fbeddbb..a8c3aace9 100644 --- a/domain/src/main/java/com/moez/QKSMS/interactor/ReceiveSms.kt +++ b/domain/src/main/java/com/moez/QKSMS/interactor/ReceiveSms.kt @@ -23,6 +23,7 @@ import com.moez.QKSMS.blocking.BlockingClient import com.moez.QKSMS.extensions.mapNotNull import com.moez.QKSMS.manager.NotificationManager import com.moez.QKSMS.manager.ShortcutManager +import com.moez.QKSMS.repository.AndroidMessagesRepository import com.moez.QKSMS.repository.ConversationRepository import com.moez.QKSMS.repository.MessageRepository import com.moez.QKSMS.util.Preferences @@ -37,7 +38,8 @@ class ReceiveSms @Inject constructor( private val messageRepo: MessageRepository, private val notificationManager: NotificationManager, private val updateBadge: UpdateBadge, - private val shortcutManager: ShortcutManager + private val shortcutManager: ShortcutManager, + private val androidMessagesRepository: AndroidMessagesRepository ) : Interactor() { class Params(val subId: Int, val messages: Array) @@ -74,7 +76,7 @@ class ReceiveSms @Inject constructor( is BlockingClient.Action.Unblock -> conversationRepo.markUnblocked(message.threadId) else -> Unit } - + androidMessagesRepository.deleteMessage(it.messages) message } .doOnNext { message -> diff --git a/domain/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt b/domain/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt new file mode 100644 index 000000000..fc6ee1686 --- /dev/null +++ b/domain/src/main/java/com/moez/QKSMS/repository/AndroidMessagesRepository.kt @@ -0,0 +1,7 @@ +package com.moez.QKSMS.repository + +import android.telephony.SmsMessage + +interface AndroidMessagesRepository { + fun deleteMessage(messages: Array) +} \ No newline at end of file diff --git a/presentation/build.gradle b/presentation/build.gradle index 7dee8d3c8..5984f3719 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -50,6 +50,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } + debug { + applicationIdSuffix '.debug' + debuggable true + minifyEnabled false + } } compileOptions { diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml index 796dc6a33..1b40d0836 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/presentation/src/main/AndroidManifest.xml @@ -39,7 +39,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file