#1236 - Allow selecting if you want to drop or save blocked messages

This commit is contained in:
moezbhatti
2019-06-04 00:14:53 -04:00
parent 14bf7d4271
commit 25aff4d7ca
10 changed files with 67 additions and 13 deletions
@@ -26,6 +26,7 @@ import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository
import com.moez.QKSMS.repository.SyncRepository
import com.moez.QKSMS.util.Preferences
import io.reactivex.Flowable
import timber.log.Timber
import javax.inject.Inject
@@ -34,6 +35,7 @@ class ReceiveMms @Inject constructor(
private val activeConversationManager: ActiveConversationManager,
private val conversationRepo: ConversationRepository,
private val blockingClient: BlockingClient,
private val prefs: Preferences,
private val syncManager: SyncRepository,
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
@@ -50,15 +52,25 @@ class ReceiveMms @Inject constructor(
messageRepo.markRead(message.threadId)
}
}
.filter { message ->
.mapNotNull { message ->
// Because we use the smsmms library for receiving and storing MMS, we'll need
// to check if it should be blocked after we've pulled it into realm. If it
// turns out that it should be blocked, then delete it
// turns out that it should be dropped, then delete it
// TODO Don't store blocked messages in the first place
!blockingClient.shouldBlock(message.address).blockingGet().also { blocked ->
Timber.v("Should block: $blocked")
if (blocked) messageRepo.deleteMessages(message.id)
val shouldBlock = blockingClient.shouldBlock(message.address).blockingGet()
val shouldDrop = prefs.drop.get()
Timber.v("block=$shouldBlock, drop=$shouldDrop")
if (shouldBlock && shouldDrop) {
messageRepo.deleteMessages(message.id)
return@mapNotNull null
}
if (shouldBlock) {
conversationRepo.markBlocked(message.threadId)
}
message
}
.doOnNext { message ->
conversationRepo.updateConversations(message.threadId) // Update the conversation
@@ -25,6 +25,7 @@ import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository
import com.moez.QKSMS.util.Preferences
import io.reactivex.Flowable
import timber.log.Timber
import javax.inject.Inject
@@ -32,6 +33,7 @@ import javax.inject.Inject
class ReceiveSms @Inject constructor(
private val conversationRepo: ConversationRepository,
private val blockingClient: BlockingClient,
private val prefs: Preferences,
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge,
@@ -43,22 +45,32 @@ class ReceiveSms @Inject constructor(
override fun buildObservable(params: Params): Flowable<*> {
return Flowable.just(params)
.filter { it.messages.isNotEmpty() }
.filter {
.mapNotNull {
// Don't continue if the sender is blocked
val address = it.messages[0].displayOriginatingAddress
val shouldBlock = blockingClient.shouldBlock(address).blockingGet()
Timber.v("Should block: $shouldBlock")
!shouldBlock
}
.map {
val messages = it.messages
val address = messages[0].displayOriginatingAddress
val shouldBlock = blockingClient.shouldBlock(address).blockingGet()
val shouldDrop = prefs.drop.get()
Timber.v("block=$shouldBlock, drop=$shouldDrop")
// If we should drop the message, don't even save it
if (shouldBlock && shouldDrop) {
return@mapNotNull null
}
val time = messages[0].timestampMillis
val body: String = messages
.mapNotNull { message -> message.displayMessageBody }
.reduce { body, new -> body + new }
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
// Add the message to the db
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
if (shouldBlock) {
conversationRepo.markBlocked(message.threadId)
}
message
}
.doOnNext { message ->
conversationRepo.updateConversations(message.threadId) // Update the conversation