forked from upstream-mirrors/quik
Don't allow incoming messages if blocked via SIA
This commit is contained in:
@@ -60,7 +60,6 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
private val messageIds: KeyManager,
|
private val messageIds: KeyManager,
|
||||||
private val cursorToConversation: CursorToConversation,
|
private val cursorToConversation: CursorToConversation,
|
||||||
private val cursorToRecipient: CursorToRecipient,
|
private val cursorToRecipient: CursorToRecipient,
|
||||||
private val externalBlockingManager: ExternalBlockingManager,
|
|
||||||
private val prefs: Preferences) : MessageRepository {
|
private val prefs: Preferences) : MessageRepository {
|
||||||
|
|
||||||
override fun getConversations(archived: Boolean): Flowable<List<Conversation>> {
|
override fun getConversations(archived: Boolean): Flowable<List<Conversation>> {
|
||||||
@@ -625,11 +624,6 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If any of the addresses here should be blocked, then block the conversation
|
|
||||||
conversation.blocked = recipients.map { it.address }.any { address ->
|
|
||||||
externalBlockingManager.shouldBlock(address).blockingGet()
|
|
||||||
}
|
|
||||||
|
|
||||||
conversation.recipients.clear()
|
conversation.recipients.clear()
|
||||||
conversation.recipients.addAll(recipients)
|
conversation.recipients.addAll(recipients)
|
||||||
conversation.insertOrUpdate()
|
conversation.insertOrUpdate()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package interactor
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
|
import manager.ExternalBlockingManager
|
||||||
import manager.NotificationManager
|
import manager.NotificationManager
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
import repository.SyncRepository
|
import repository.SyncRepository
|
||||||
@@ -28,6 +29,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ReceiveMms @Inject constructor(
|
class ReceiveMms @Inject constructor(
|
||||||
|
private val externalBlockingManager: ExternalBlockingManager,
|
||||||
private val syncManager: SyncRepository,
|
private val syncManager: SyncRepository,
|
||||||
private val messageRepo: MessageRepository,
|
private val messageRepo: MessageRepository,
|
||||||
private val notificationManager: NotificationManager,
|
private val notificationManager: NotificationManager,
|
||||||
@@ -37,6 +39,15 @@ class ReceiveMms @Inject constructor(
|
|||||||
override fun buildObservable(params: Uri): Flowable<*> {
|
override fun buildObservable(params: Uri): Flowable<*> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
|
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
|
||||||
|
.filter { 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
|
||||||
|
// TODO Don't store blocked messages in the first place
|
||||||
|
!externalBlockingManager.shouldBlock(message.address).blockingGet().also { blocked ->
|
||||||
|
if (blocked) messageRepo.deleteMessage(message.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
||||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||||
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package interactor
|
|||||||
|
|
||||||
import android.telephony.SmsMessage
|
import android.telephony.SmsMessage
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
|
import manager.ExternalBlockingManager
|
||||||
import manager.NotificationManager
|
import manager.NotificationManager
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
import util.extensions.mapNotNull
|
import util.extensions.mapNotNull
|
||||||
@@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ReceiveSms @Inject constructor(
|
class ReceiveSms @Inject constructor(
|
||||||
|
private val externalBlockingManager: ExternalBlockingManager,
|
||||||
private val messageRepo: MessageRepository,
|
private val messageRepo: MessageRepository,
|
||||||
private val notificationManager: NotificationManager,
|
private val notificationManager: NotificationManager,
|
||||||
private val updateBadge: UpdateBadge
|
private val updateBadge: UpdateBadge
|
||||||
@@ -35,6 +37,10 @@ class ReceiveSms @Inject constructor(
|
|||||||
override fun buildObservable(params: Array<SmsMessage>): Flowable<*> {
|
override fun buildObservable(params: Array<SmsMessage>): Flowable<*> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
|
.filter { messages -> // Don't continue if the sender is blocked
|
||||||
|
val address = messages[0].displayOriginatingAddress
|
||||||
|
!externalBlockingManager.shouldBlock(address).blockingGet()
|
||||||
|
}
|
||||||
.map { messages ->
|
.map { messages ->
|
||||||
val address = messages[0].displayOriginatingAddress
|
val address = messages[0].displayOriginatingAddress
|
||||||
val time = messages[0].timestampMillis
|
val time = messages[0].timestampMillis
|
||||||
|
|||||||
Reference in New Issue
Block a user