mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Merge pull request #496 from peanut250/feat/message-content-filters
Block messages based on content
This commit is contained in:
@@ -23,7 +23,9 @@ import dev.octoshrimpy.quik.blocking.BlockingClient
|
||||
import dev.octoshrimpy.quik.extensions.mapNotNull
|
||||
import dev.octoshrimpy.quik.manager.ActiveConversationManager
|
||||
import dev.octoshrimpy.quik.manager.NotificationManager
|
||||
import dev.octoshrimpy.quik.repository.ContactRepository
|
||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageContentFilterRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import dev.octoshrimpy.quik.repository.SyncRepository
|
||||
import dev.octoshrimpy.quik.util.Preferences
|
||||
@@ -39,7 +41,9 @@ class ReceiveMms @Inject constructor(
|
||||
private val syncManager: SyncRepository,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
private val updateBadge: UpdateBadge
|
||||
private val updateBadge: UpdateBadge,
|
||||
private val filterRepo: MessageContentFilterRepository,
|
||||
private val contactsRepo: ContactRepository
|
||||
) : Interactor<Uri>() {
|
||||
|
||||
override fun buildObservable(params: Uri): Flowable<*> {
|
||||
@@ -75,6 +79,12 @@ class ReceiveMms @Inject constructor(
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
if (filterRepo.isBlocked(message.getText(), message.address, contactsRepo)) {
|
||||
Timber.v("message dropped based on content filters")
|
||||
messageRepo.deleteMessages(listOf(message.id))
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
message
|
||||
}
|
||||
.doOnNext { message ->
|
||||
|
||||
@@ -22,7 +22,9 @@ import dev.octoshrimpy.quik.blocking.BlockingClient
|
||||
import dev.octoshrimpy.quik.extensions.mapNotNull
|
||||
import dev.octoshrimpy.quik.manager.NotificationManager
|
||||
import dev.octoshrimpy.quik.manager.ShortcutManager
|
||||
import dev.octoshrimpy.quik.repository.ContactRepository
|
||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageContentFilterRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import dev.octoshrimpy.quik.util.Preferences
|
||||
import io.reactivex.Flowable
|
||||
@@ -36,7 +38,9 @@ class ReceiveSms @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
private val updateBadge: UpdateBadge,
|
||||
private val shortcutManager: ShortcutManager
|
||||
private val shortcutManager: ShortcutManager,
|
||||
private val filterRepo: MessageContentFilterRepository,
|
||||
private val contactsRepo: ContactRepository
|
||||
) : Interactor<Long>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
@@ -69,6 +73,12 @@ class ReceiveSms @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
if (filterRepo.isBlocked(it.getText(), it.address, contactsRepo)) {
|
||||
Timber.v("message dropped based on content filters")
|
||||
messageRepo.deleteMessages(listOf(it.id))
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
// update and fetch conversation
|
||||
conversationRepo.updateConversations(it.threadId)
|
||||
conversationRepo.getOrCreateConversation(it.threadId)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.octoshrimpy.quik.model
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
open class MessageContentFilter(
|
||||
@PrimaryKey var id: Long = 0,
|
||||
|
||||
var value: String = "",
|
||||
var caseSensitive: Boolean = false,
|
||||
var isRegex: Boolean = false,
|
||||
var includeContacts: Boolean = false
|
||||
) : RealmObject()
|
||||
|
||||
data class MessageContentFilterData(
|
||||
var value: String = "",
|
||||
var caseSensitive: Boolean = false,
|
||||
var isRegex: Boolean = false,
|
||||
var includeContacts: Boolean = false
|
||||
)
|
||||
@@ -41,4 +41,6 @@ interface ContactRepository {
|
||||
|
||||
fun setDefaultPhoneNumber(lookupKey: String, phoneNumberId: Long)
|
||||
|
||||
fun isContact(address: String): Boolean
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 dev.octoshrimpy.quik.repository
|
||||
|
||||
import dev.octoshrimpy.quik.model.MessageContentFilter
|
||||
import dev.octoshrimpy.quik.model.MessageContentFilterData
|
||||
import io.realm.RealmResults
|
||||
|
||||
interface MessageContentFilterRepository {
|
||||
|
||||
fun createFilter(data: MessageContentFilterData)
|
||||
|
||||
fun getMessageContentFilters(): RealmResults<MessageContentFilter>
|
||||
|
||||
fun getMessageContentFilter(id: Long): MessageContentFilter?
|
||||
|
||||
fun isBlocked(messageBody: String, address: String, contactsRepo: ContactRepository): Boolean
|
||||
|
||||
fun removeFilter(id: Long)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user