Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d46193ab authored by moezbhatti's avatar moezbhatti
Browse files

Show blocking reason if available

parent 56d13dfe
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -50,15 +50,15 @@ class CallControlBlockingClient @Inject constructor(

    override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
        val uri = Uri.withAppendedPath(CallControl.LOOKUP_TEXT_URI, address)
        val blocked = tryOrNull {
        val blockReason = tryOrNull {
            context.contentResolver.query(uri, projection, null, null, null) // Query URI
                    ?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
                    ?.any { result -> result.blockReason != null } // Check if any are blocked
        } == true // If none are blocked or we errored at some point, return false
                    ?.find { result -> result.blockReason != null } // Check if any are blocked
        }?.blockReason // If none are blocked or we errored at some point, return false

        when (blocked) {
            true -> BlockingClient.Action.BLOCK
            false -> BlockingClient.Action.UNBLOCK
        when (blockReason) {
            null -> BlockingClient.Action.Unblock
            else -> BlockingClient.Action.Block(blockReason)
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@ class QksmsBlockingClient @Inject constructor(

    override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
        when (blockingRepo.isBlocked(address)) {
            true -> BlockingClient.Action.BLOCK
            false -> BlockingClient.Action.UNBLOCK
            true -> BlockingClient.Action.Block()
            false -> BlockingClient.Action.Unblock
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ class ShouldIAnswerBlockingClient @Inject constructor(
        return Binder(context, address).isBlocked()
                .map { blocked ->
                    when (blocked) {
                        true -> BlockingClient.Action.BLOCK
                        false -> BlockingClient.Action.DO_NOTHING
                        true -> BlockingClient.Action.Block()
                        false -> BlockingClient.Action.DoNothing
                    }
                }
    }
+10 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import io.realm.RealmMigration
class QkRealmMigration : RealmMigration {

    companion object {
        const val SCHEMA_VERSION: Long = 6
        const val SCHEMA_VERSION: Long = 7
    }

    override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
@@ -80,6 +80,14 @@ class QkRealmMigration : RealmMigration {
            version++
        }

        if (version == 6L) {
            realm.schema.get("Conversation")
                    ?.addField("blockingClient", Integer::class.java)
                    ?.addField("blockReason", String::class.java)

            version++
        }

        if (version < newVersion) {
            throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
        }
+13 −4
Original line number Diff line number Diff line
@@ -297,14 +297,19 @@ class ConversationRepositoryImpl @Inject constructor(
        }
    }

    override fun markBlocked(vararg threadIds: Long) {
    override fun markBlocked(threadIds: List<Long>, blockingClient: Int, blockReason: String?) {
        Realm.getDefaultInstance().use { realm ->
            val conversations = realm.where(Conversation::class.java)
                    .anyOf("id", threadIds)
                    .anyOf("id", threadIds.toLongArray())
                    .equalTo("blocked", false)
                    .findAll()

            realm.executeTransaction {
                conversations.forEach { it.blocked = true }
                conversations.forEach { conversation ->
                    conversation.blocked = true
                    conversation.blockingClient = blockingClient
                    conversation.blockReason = blockReason
                }
            }
        }
    }
@@ -316,7 +321,11 @@ class ConversationRepositoryImpl @Inject constructor(
                    .findAll()

            realm.executeTransaction {
                conversations.forEach { it.blocked = false }
                conversations.forEach { conversation ->
                    conversation.blocked = false
                    conversation.blockingClient = null
                    conversation.blockReason = null
                }
            }
        }
    }
Loading