mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Don't unblock numbers not reported by SIA
This commit is contained in:
@@ -23,6 +23,22 @@ import io.reactivex.Single
|
||||
|
||||
interface BlockingClient {
|
||||
|
||||
enum class Capability {
|
||||
BLOCK_WITHOUT_PERMISSION,
|
||||
BLOCK_WITH_PERMISSION ,
|
||||
CANT_BLOCK
|
||||
}
|
||||
|
||||
enum class Action {
|
||||
BLOCK,
|
||||
UNBLOCK,
|
||||
|
||||
// We only need these for Should I Answer, because they don't allow us to block numbers in their app directly.
|
||||
// This means there's a good chance that if a number is blocked in QK, it won't be blocked there, so we
|
||||
// shouldn't unblock the conversation in that case
|
||||
DO_NOTHING
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the target blocking client is available for use, ie. it is installed
|
||||
*/
|
||||
@@ -31,12 +47,12 @@ interface BlockingClient {
|
||||
/**
|
||||
* Returns the level of access that the given blocking client provides to QKSMS
|
||||
*/
|
||||
fun getClientCapability(): BlockingClientCapability
|
||||
fun getClientCapability(): Capability
|
||||
|
||||
/**
|
||||
* Return a Single<Boolean> which emits whether or not the given [address] should be blocked
|
||||
* Returns the recommendation action to perform given a message from the [address]
|
||||
*/
|
||||
fun isBlocked(address: String): Single<Boolean>
|
||||
fun getAction(address: String): Single<Action>
|
||||
|
||||
/**
|
||||
* Blocks the numbers or opens the manager
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.blocking
|
||||
|
||||
enum class BlockingClientCapability {
|
||||
BLOCK_WITHOUT_PERMISSION,
|
||||
BLOCK_WITH_PERMISSION ,
|
||||
CANT_BLOCK
|
||||
}
|
||||
@@ -57,19 +57,19 @@ class ReceiveMms @Inject constructor(
|
||||
// to check if it should be blocked after we've pulled it into realm. If it
|
||||
// turns out that it should be dropped, then delete it
|
||||
// TODO Don't store blocked messages in the first place
|
||||
val shouldBlock = blockingClient.isBlocked(message.address).blockingGet()
|
||||
val action = blockingClient.getAction(message.address).blockingGet()
|
||||
val shouldDrop = prefs.drop.get()
|
||||
Timber.v("block=$shouldBlock, drop=$shouldDrop")
|
||||
Timber.v("block=$action, drop=$shouldDrop")
|
||||
|
||||
if (shouldBlock && shouldDrop) {
|
||||
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
|
||||
messageRepo.deleteMessages(message.id)
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
if (shouldBlock) {
|
||||
conversationRepo.markBlocked(message.threadId)
|
||||
} else {
|
||||
conversationRepo.markUnblocked(message.threadId)
|
||||
when (action) {
|
||||
BlockingClient.Action.BLOCK -> conversationRepo.markBlocked(message.threadId)
|
||||
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
message
|
||||
|
||||
@@ -49,12 +49,12 @@ class ReceiveSms @Inject constructor(
|
||||
// Don't continue if the sender is blocked
|
||||
val messages = it.messages
|
||||
val address = messages[0].displayOriginatingAddress
|
||||
val shouldBlock = blockingClient.isBlocked(address).blockingGet()
|
||||
val action = blockingClient.getAction(address).blockingGet()
|
||||
val shouldDrop = prefs.drop.get()
|
||||
Timber.v("block=$shouldBlock, drop=$shouldDrop")
|
||||
Timber.v("block=$action, drop=$shouldDrop")
|
||||
|
||||
// If we should drop the message, don't even save it
|
||||
if (shouldBlock && shouldDrop) {
|
||||
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ class ReceiveSms @Inject constructor(
|
||||
// Add the message to the db
|
||||
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
|
||||
|
||||
if (shouldBlock) {
|
||||
conversationRepo.markBlocked(message.threadId)
|
||||
} else {
|
||||
conversationRepo.markUnblocked(message.threadId)
|
||||
when (action) {
|
||||
BlockingClient.Action.BLOCK -> conversationRepo.markBlocked(message.threadId)
|
||||
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
message
|
||||
|
||||
Reference in New Issue
Block a user