FossifyOrg / Messages

An easy and quick way of managing SMS and MMS messages without ads.
https://www.fossify.org
GNU General Public License v3.0
414 stars 29 forks source link

[FEATURE] Stored/known contacts ignore blocked keywords #181

Open sudoshindo opened 3 weeks ago

sudoshindo commented 3 weeks ago

Checklist

Feature description

New checkbox/toggle in settings labeled "Stored contacts ignore blocked keywords" (tentative)

Behavior:

If enabled, only apply keyword blocking to not stored contacts.

If disabled, apply keyword blocking globally (this is the default behavior).

Why do you want this feature?

More fine tuned control over keyword blocking.

Additional information

⚠️ TREAT THIS AS PSEUDO-CODE ⚠️ ⚠️ THIS IS UNTESTED, I'VE NEVER CODED FOR ANDROID ⚠️

I don't have a Kotlin development environment. I just did this to increase the chances of getting accepted/implemented.

SmsReceiver.kt

// I DON'T KNOW HOW/WHERE TO PROPERLY DECLARE THIS VARIABLE
context.baseConfig.knownNumbersIgnoreKeywords = false

private fun isMessageFilteredOut(context: Context, body: String): Boolean {
    val simpleContactsHelper = SimpleContactsHelper(context)
    simpleContactsHelper.exists(address, privateCursor) { exists ->

        // don't filter if sender is known and setting is enabled
        if (exists && context.baseConfig.knownNumbersIgnoreKeywords) {
            return false
        }

    }

    // resume original function behavior
    for (blockedKeyword in context.config.blockedKeywords) {
        if (body.contains(blockedKeyword, ignoreCase = true)) {
            return true
        }
    }

    return false
}
sudoshindo commented 3 weeks ago

Updated sample code, less confusing if-statement structure. Updated text in "Additional information" section.

tve commented 2 weeks ago

the fact that messages from my contacts are blocked because they match a keyword is baffling to me. I don't want messages from contacts blocked, it makes the keyword list almost useless. In other words: +1 for this feature.

sudoshindo commented 2 weeks ago

I have no idea how this will affect alphanumeric Sender IDs though. Like when you receive a message from your network provider and the sender isn't a number but it automatically has its own name even if it's not a saved in your contacts.

IDK if Android treats that as known or unknown.