Show blocking reason if available

This commit is contained in:
moezbhatti
2019-10-10 19:15:38 -04:00
parent 56d13dfe3e
commit d46193abba
16 changed files with 182 additions and 80 deletions
@@ -25,12 +25,16 @@ import javax.inject.Inject
class MarkBlocked @Inject constructor(
private val conversationRepo: ConversationRepository,
private val markRead: MarkRead
) : Interactor<List<Long>>() {
) : Interactor<MarkBlocked.Params>() {
override fun buildObservable(params: List<Long>): Flowable<*> {
return Flowable.just(params.toLongArray())
.doOnNext { threadIds -> conversationRepo.markBlocked(*threadIds) }
.flatMap { markRead.buildObservable(params) }
data class Params(val threadIds: List<Long>, val blockingClient: Int, val blockReason: String?)
override fun buildObservable(params: Params): Flowable<*> {
return Flowable.just(params)
.doOnNext { (threadIds, blockingClient, blockReason) ->
conversationRepo.markBlocked(threadIds, blockingClient, blockReason)
}
.flatMap { (threadIds) -> markRead.buildObservable(threadIds) }
}
}
}
@@ -61,17 +61,17 @@ class ReceiveMms @Inject constructor(
val shouldDrop = prefs.drop.get()
Timber.v("block=$action, drop=$shouldDrop")
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
if (action is BlockingClient.Action.Block && shouldDrop) {
messageRepo.deleteMessages(message.id)
return@mapNotNull null
}
when (action) {
BlockingClient.Action.BLOCK -> {
is BlockingClient.Action.Block -> {
messageRepo.markRead(message.threadId)
conversationRepo.markBlocked(message.threadId)
conversationRepo.markBlocked(listOf(message.threadId), prefs.blockingManager.get(), action.reason)
}
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
is BlockingClient.Action.Unblock -> conversationRepo.markUnblocked(message.threadId)
else -> Unit
}
@@ -54,7 +54,7 @@ class ReceiveSms @Inject constructor(
Timber.v("block=$action, drop=$shouldDrop")
// If we should drop the message, don't even save it
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
if (action is BlockingClient.Action.Block && shouldDrop) {
return@mapNotNull null
}
@@ -67,11 +67,11 @@ class ReceiveSms @Inject constructor(
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
when (action) {
BlockingClient.Action.BLOCK -> {
is BlockingClient.Action.Block -> {
messageRepo.markRead(message.threadId)
conversationRepo.markBlocked(message.threadId)
conversationRepo.markBlocked(listOf(message.threadId), prefs.blockingManager.get(), action.reason)
}
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
is BlockingClient.Action.Unblock -> conversationRepo.markUnblocked(message.threadId)
else -> Unit
}