separated spam and report filter options

This commit is contained in:
greenart7c3
2023-06-12 07:38:32 -03:00
parent f0638b1766
commit 8f668cb5fb
7 changed files with 47 additions and 21 deletions

View File

@@ -61,7 +61,8 @@ private object PrefKeys {
const val USE_PROXY = "use_proxy" const val USE_PROXY = "use_proxy"
const val PROXY_PORT = "proxy_port" const val PROXY_PORT = "proxy_port"
const val SHOW_SENSITIVE_CONTENT = "show_sensitive_content" const val SHOW_SENSITIVE_CONTENT = "show_sensitive_content"
const val OPT_OUT_FILTERS = "opt_out_filters" const val WARN_ABOUT_REPORTS = "warn_about_reports"
const val FILTER_SPAM_FROM_STRANGERS = "filter_spam_from_strangers"
val LAST_READ: (String) -> String = { route -> "last_read_route_$route" } val LAST_READ: (String) -> String = { route -> "last_read_route_$route" }
} }
@@ -218,7 +219,8 @@ object LocalPreferences {
putBoolean(PrefKeys.HIDE_BLOCK_ALERT_DIALOG, account.hideBlockAlertDialog) putBoolean(PrefKeys.HIDE_BLOCK_ALERT_DIALOG, account.hideBlockAlertDialog)
putBoolean(PrefKeys.USE_PROXY, account.proxy != null) putBoolean(PrefKeys.USE_PROXY, account.proxy != null)
putInt(PrefKeys.PROXY_PORT, account.proxyPort) putInt(PrefKeys.PROXY_PORT, account.proxyPort)
putBoolean(PrefKeys.OPT_OUT_FILTERS, account.optOutFromFilters) putBoolean(PrefKeys.WARN_ABOUT_REPORTS, account.warnAboutPostsWithReports)
putBoolean(PrefKeys.FILTER_SPAM_FROM_STRANGERS, account.filterSpamFromStrangers)
if (account.showSensitiveContent == null) { if (account.showSensitiveContent == null) {
remove(PrefKeys.SHOW_SENSITIVE_CONTENT) remove(PrefKeys.SHOW_SENSITIVE_CONTENT)
@@ -308,7 +310,8 @@ object LocalPreferences {
} else { } else {
null null
} }
val optOutFromFilters = getBoolean(PrefKeys.OPT_OUT_FILTERS, false) val filterSpam = getBoolean(PrefKeys.FILTER_SPAM_FROM_STRANGERS, true)
val warnAboutReports = getBoolean(PrefKeys.WARN_ABOUT_REPORTS, true)
val a = Account( val a = Account(
Persona(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray()), Persona(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray()),
@@ -331,7 +334,8 @@ object LocalPreferences {
proxy, proxy,
proxyPort, proxyPort,
showSensitiveContent, showSensitiveContent,
optOutFromFilters warnAboutReports,
filterSpam
) )
return a return a

View File

@@ -1,9 +1,11 @@
package com.vitorpamplona.amethyst package com.vitorpamplona.amethyst
object OptOutFromFilters { object OptOutFromFilters {
var optOutFromFilters: Boolean = false var warnAboutPostsWithReports: Boolean = true
var filterSpamFromStrangers: Boolean = true
fun start(optOut: Boolean) { fun start(warnAboutReports: Boolean, filterSpam: Boolean) {
optOutFromFilters = optOut warnAboutPostsWithReports = warnAboutReports
filterSpamFromStrangers = filterSpam
} }
} }

View File

@@ -36,7 +36,7 @@ object ServiceManager {
// Resets Proxy Use // Resets Proxy Use
HttpClient.start(account) HttpClient.start(account)
OptOutFromFilters.start(account?.optOutFromFilters ?: false) OptOutFromFilters.start(account?.warnAboutPostsWithReports ?: true, account?.filterSpamFromStrangers ?: true)
Coil.setImageLoader { Coil.setImageLoader {
ImageLoader.Builder(context).components { ImageLoader.Builder(context).components {
if (Build.VERSION.SDK_INT >= 28) { if (Build.VERSION.SDK_INT >= 28) {

View File

@@ -68,7 +68,8 @@ class Account(
var proxy: Proxy?, var proxy: Proxy?,
var proxyPort: Int, var proxyPort: Int,
var showSensitiveContent: Boolean? = null, var showSensitiveContent: Boolean? = null,
var optOutFromFilters: Boolean = false var warnAboutPostsWithReports: Boolean = true,
var filterSpamFromStrangers: Boolean = true
) { ) {
var transientHiddenUsers: Set<String> = setOf() var transientHiddenUsers: Set<String> = setOf()
@@ -79,9 +80,13 @@ class Account(
var userProfileCache: User? = null var userProfileCache: User? = null
fun updateOptOutFromFilters(value: Boolean) { fun updateOptOutOptions(warnReports: Boolean, filterSpam: Boolean) {
optOutFromFilters = value warnAboutPostsWithReports = warnReports
OptOutFromFilters.start(optOutFromFilters) filterSpamFromStrangers = filterSpam
OptOutFromFilters.start(warnAboutPostsWithReports, filterSpamFromStrangers)
if (!filterSpamFromStrangers) {
transientHiddenUsers = setOf()
}
live.invalidateData() live.invalidateData()
saveable.invalidateData() saveable.invalidateData()
} }
@@ -1066,7 +1071,7 @@ class Account(
} }
fun isAcceptable(user: User): Boolean { fun isAcceptable(user: User): Boolean {
if (optOutFromFilters) { if (!warnAboutPostsWithReports) {
return !isHidden(user) && // if user hasn't hided this author return !isHidden(user) && // if user hasn't hided this author
user.reportsBy(userProfile()).isEmpty() // if user has not reported this post user.reportsBy(userProfile()).isEmpty() // if user has not reported this post
} }
@@ -1076,7 +1081,7 @@ class Account(
} }
fun isAcceptableDirect(note: Note): Boolean { fun isAcceptableDirect(note: Note): Boolean {
if (optOutFromFilters) { if (!warnAboutPostsWithReports) {
return note.reportsBy(userProfile()).isEmpty() return note.reportsBy(userProfile()).isEmpty()
} }
return note.reportsBy(userProfile()).isEmpty() && // if user has not reported this post return note.reportsBy(userProfile()).isEmpty() && // if user has not reported this post

View File

@@ -21,7 +21,7 @@ class AntiSpamFilter {
fun isSpam(event: Event, relay: Relay?): Boolean { fun isSpam(event: Event, relay: Relay?): Boolean {
checkNotInMainThread() checkNotInMainThread()
if (OptOutFromFilters.optOutFromFilters) return false if (!OptOutFromFilters.filterSpamFromStrangers) return false
val idHex = event.id val idHex = event.id

View File

@@ -74,19 +74,33 @@ fun HiddenUsersScreen(
Column(modifier = Modifier.padding(start = 10.dp, end = 10.dp)) { Column(modifier = Modifier.padding(start = 10.dp, end = 10.dp)) {
val pagerState = rememberPagerState() val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
var checked by remember { mutableStateOf(accountViewModel.account.optOutFromFilters) } var warnAboutReports by remember { mutableStateOf(accountViewModel.account.warnAboutPostsWithReports) }
var filterSpam by remember { mutableStateOf(accountViewModel.account.filterSpamFromStrangers) }
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox( Checkbox(
checked = checked, checked = warnAboutReports,
onCheckedChange = { onCheckedChange = {
checked = it warnAboutReports = it
accountViewModel.account.updateOptOutFromFilters(checked) accountViewModel.account.updateOptOutOptions(warnAboutReports, filterSpam)
LocalPreferences.saveToEncryptedStorage(accountViewModel.account) LocalPreferences.saveToEncryptedStorage(accountViewModel.account)
} }
) )
Text(stringResource(R.string.opt_out_from_filters)) Text(stringResource(R.string.warn_when_posts_have_reports_from_your_follows))
}
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(
checked = filterSpam,
onCheckedChange = {
filterSpam = it
accountViewModel.account.updateOptOutOptions(warnAboutReports, filterSpam)
LocalPreferences.saveToEncryptedStorage(accountViewModel.account)
}
)
Text(stringResource(R.string.filter_spam_from_strangers))
} }
TabRow( TabRow(

View File

@@ -412,5 +412,6 @@
<string name="content_warning_see_warnings">Always show content warnings</string> <string name="content_warning_see_warnings">Always show content warnings</string>
<string name="recommended_apps">Recommends: </string> <string name="recommended_apps">Recommends: </string>
<string name="opt_out_from_filters">Opt-out from automatic filters</string> <string name="filter_spam_from_strangers">Filter spam from strangers</string>
<string name="warn_when_posts_have_reports_from_your_follows">Warn when posts have reports from your follows</string>
</resources> </resources>