mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
#1236 - Allow selecting if you want to drop or save blocked messages
This commit is contained in:
@@ -26,6 +26,7 @@ import com.moez.QKSMS.manager.NotificationManager
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.repository.SyncRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.Flowable
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -34,6 +35,7 @@ class ReceiveMms @Inject constructor(
|
||||
private val activeConversationManager: ActiveConversationManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val blockingClient: BlockingClient,
|
||||
private val prefs: Preferences,
|
||||
private val syncManager: SyncRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
@@ -50,15 +52,25 @@ class ReceiveMms @Inject constructor(
|
||||
messageRepo.markRead(message.threadId)
|
||||
}
|
||||
}
|
||||
.filter { message ->
|
||||
.mapNotNull { 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
|
||||
// turns out that it should be dropped, then delete it
|
||||
// TODO Don't store blocked messages in the first place
|
||||
!blockingClient.shouldBlock(message.address).blockingGet().also { blocked ->
|
||||
Timber.v("Should block: $blocked")
|
||||
if (blocked) messageRepo.deleteMessages(message.id)
|
||||
val shouldBlock = blockingClient.shouldBlock(message.address).blockingGet()
|
||||
val shouldDrop = prefs.drop.get()
|
||||
Timber.v("block=$shouldBlock, drop=$shouldDrop")
|
||||
|
||||
if (shouldBlock && shouldDrop) {
|
||||
messageRepo.deleteMessages(message.id)
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
if (shouldBlock) {
|
||||
conversationRepo.markBlocked(message.threadId)
|
||||
}
|
||||
|
||||
message
|
||||
}
|
||||
.doOnNext { message ->
|
||||
conversationRepo.updateConversations(message.threadId) // Update the conversation
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.moez.QKSMS.manager.NotificationManager
|
||||
import com.moez.QKSMS.manager.ShortcutManager
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.Flowable
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -32,6 +33,7 @@ import javax.inject.Inject
|
||||
class ReceiveSms @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val blockingClient: BlockingClient,
|
||||
private val prefs: Preferences,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
private val updateBadge: UpdateBadge,
|
||||
@@ -43,22 +45,32 @@ class ReceiveSms @Inject constructor(
|
||||
override fun buildObservable(params: Params): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.filter { it.messages.isNotEmpty() }
|
||||
.filter {
|
||||
.mapNotNull {
|
||||
// Don't continue if the sender is blocked
|
||||
val address = it.messages[0].displayOriginatingAddress
|
||||
val shouldBlock = blockingClient.shouldBlock(address).blockingGet()
|
||||
Timber.v("Should block: $shouldBlock")
|
||||
!shouldBlock
|
||||
}
|
||||
.map {
|
||||
val messages = it.messages
|
||||
val address = messages[0].displayOriginatingAddress
|
||||
val shouldBlock = blockingClient.shouldBlock(address).blockingGet()
|
||||
val shouldDrop = prefs.drop.get()
|
||||
Timber.v("block=$shouldBlock, drop=$shouldDrop")
|
||||
|
||||
// If we should drop the message, don't even save it
|
||||
if (shouldBlock && shouldDrop) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
val time = messages[0].timestampMillis
|
||||
val body: String = messages
|
||||
.mapNotNull { message -> message.displayMessageBody }
|
||||
.reduce { body, new -> body + new }
|
||||
|
||||
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
|
||||
// Add the message to the db
|
||||
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
|
||||
|
||||
if (shouldBlock) {
|
||||
conversationRepo.markBlocked(message.threadId)
|
||||
}
|
||||
|
||||
message
|
||||
}
|
||||
.doOnNext { message ->
|
||||
conversationRepo.updateConversations(message.threadId) // Update the conversation
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.util
|
||||
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import com.f2prateek.rx.preferences2.Preference
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences) {
|
||||
|
||||
companion object {
|
||||
const val NIGHT_MODE_SYSTEM = 0
|
||||
const val NIGHT_MODE_OFF = 1
|
||||
const val NIGHT_MODE_ON = 2
|
||||
const val NIGHT_MODE_AUTO = 3
|
||||
|
||||
const val TEXT_SIZE_SMALL = 0
|
||||
const val TEXT_SIZE_NORMAL = 1
|
||||
const val TEXT_SIZE_LARGE = 2
|
||||
const val TEXT_SIZE_LARGER = 3
|
||||
|
||||
const val NOTIFICATION_PREVIEWS_ALL = 0
|
||||
const val NOTIFICATION_PREVIEWS_NAME = 1
|
||||
const val NOTIFICATION_PREVIEWS_NONE = 2
|
||||
|
||||
const val NOTIFICATION_ACTION_NONE = 0
|
||||
const val NOTIFICATION_ACTION_READ = 1
|
||||
const val NOTIFICATION_ACTION_REPLY = 2
|
||||
const val NOTIFICATION_ACTION_CALL = 3
|
||||
const val NOTIFICATION_ACTION_DELETE = 4
|
||||
|
||||
const val SEND_DELAY_NONE = 0
|
||||
const val SEND_DELAY_SHORT = 1
|
||||
const val SEND_DELAY_MEDIUM = 2
|
||||
const val SEND_DELAY_LONG = 3
|
||||
|
||||
const val SWIPE_ACTION_NONE = 0
|
||||
const val SWIPE_ACTION_ARCHIVE = 1
|
||||
const val SWIPE_ACTION_DELETE = 2
|
||||
const val SWIPE_ACTION_CALL = 3
|
||||
const val SWIPE_ACTION_READ = 4
|
||||
const val SWIPE_ACTION_UNREAD = 5
|
||||
}
|
||||
|
||||
// Internal
|
||||
val night = rxPrefs.getBoolean("night", false)
|
||||
val canUseSubId = rxPrefs.getBoolean("canUseSubId", true)
|
||||
|
||||
// User configurable
|
||||
val nightMode = rxPrefs.getInteger("nightMode", when (Build.VERSION.SDK_INT >= 29) {
|
||||
true -> NIGHT_MODE_SYSTEM
|
||||
false -> NIGHT_MODE_OFF
|
||||
})
|
||||
val nightStart = rxPrefs.getString("nightStart", "18:00")
|
||||
val nightEnd = rxPrefs.getString("nightEnd", "6:00")
|
||||
val black = rxPrefs.getBoolean("black", false)
|
||||
val systemFont = rxPrefs.getBoolean("systemFont", false)
|
||||
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
|
||||
val callControl = rxPrefs.getBoolean("callControl", false)
|
||||
val sia = rxPrefs.getBoolean("sia", false)
|
||||
val drop = rxPrefs.getBoolean("drop", false)
|
||||
val notifAction1 = rxPrefs.getInteger("notifAction1", NOTIFICATION_ACTION_READ)
|
||||
val notifAction2 = rxPrefs.getInteger("notifAction2", NOTIFICATION_ACTION_REPLY)
|
||||
val notifAction3 = rxPrefs.getInteger("notifAction3", NOTIFICATION_ACTION_NONE)
|
||||
val qkreply = rxPrefs.getBoolean("qkreply", Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||
val qkreplyTapDismiss = rxPrefs.getBoolean("qkreplyTapDismiss", true)
|
||||
val sendDelay = rxPrefs.getInteger("sendDelay", SEND_DELAY_NONE)
|
||||
val swipeRight = rxPrefs.getInteger("swipeRight", SWIPE_ACTION_ARCHIVE)
|
||||
val swipeLeft = rxPrefs.getInteger("swipeLeft", SWIPE_ACTION_ARCHIVE)
|
||||
val autoEmoji = rxPrefs.getBoolean("autoEmoji", true)
|
||||
val delivery = rxPrefs.getBoolean("delivery", false)
|
||||
val signature = rxPrefs.getString("signature", "")
|
||||
val unicode = rxPrefs.getBoolean("unicode", false)
|
||||
val mobileOnly = rxPrefs.getBoolean("mobileOnly", false)
|
||||
val mmsSize = rxPrefs.getInteger("mmsSize", 300)
|
||||
val logging = rxPrefs.getBoolean("logging", false)
|
||||
val version = rxPrefs.getInteger("version", 0)
|
||||
|
||||
init {
|
||||
// Migrate from old night mode preference to new one, now that we support android Q night mode
|
||||
val nightModeSummary = rxPrefs.getInteger("nightModeSummary")
|
||||
if (nightModeSummary.isSet) {
|
||||
nightMode.set(when (nightModeSummary.get()) {
|
||||
0 -> NIGHT_MODE_OFF
|
||||
1 -> NIGHT_MODE_ON
|
||||
2 -> NIGHT_MODE_AUTO
|
||||
else -> NIGHT_MODE_OFF
|
||||
})
|
||||
nightModeSummary.delete()
|
||||
}
|
||||
}
|
||||
|
||||
fun theme(threadId: Long = 0): Preference<Int> {
|
||||
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getInteger("theme_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun notifications(threadId: Long = 0): Preference<Boolean> {
|
||||
val default = rxPrefs.getBoolean("notifications", true)
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getBoolean("notifications_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun notificationPreviews(threadId: Long = 0): Preference<Int> {
|
||||
val default = rxPrefs.getInteger("notification_previews", 0)
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getInteger("notification_previews_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun vibration(threadId: Long = 0): Preference<Boolean> {
|
||||
val default = rxPrefs.getBoolean("vibration", true)
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getBoolean("vibration$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun ringtone(threadId: Long = 0): Preference<String> {
|
||||
val default = rxPrefs.getString("ringtone", Settings.System.DEFAULT_NOTIFICATION_URI.toString())
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getString("ringtone_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user