mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Show blocking reason if available
This commit is contained in:
@@ -29,14 +29,14 @@ interface BlockingClient {
|
||||
CANT_BLOCK
|
||||
}
|
||||
|
||||
enum class Action {
|
||||
BLOCK,
|
||||
UNBLOCK,
|
||||
sealed class Action {
|
||||
class Block(val reason: String? = null) : Action()
|
||||
object Unblock : Action()
|
||||
|
||||
// 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
|
||||
object DoNothing : Action()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ open class Conversation(
|
||||
var me: Boolean = false,
|
||||
var draft: String = "",
|
||||
|
||||
var blockingClient: Int? = null,
|
||||
var blockReason: String? = null,
|
||||
|
||||
var name: String = "" // For group chats, the user is allowed to set a custom title for the conversation
|
||||
) : RealmObject() {
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ interface ConversationRepository {
|
||||
|
||||
fun markUnpinned(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(vararg threadIds: Long)
|
||||
fun markBlocked(threadIds: List<Long>, blockingClient: Int, blockReason: String?)
|
||||
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user