Add tags blacklist option for suggestions

This commit is contained in:
Koitharu
2022-04-08 14:56:45 +03:00
parent 6ca9608a80
commit c92bdae842
12 changed files with 230 additions and 2 deletions

View File

@@ -76,7 +76,10 @@ class SuggestionsWorker(appContext: Context, params: WorkerParameters) :
suggestionRepository.clear()
return 0
}
val allTags = historyRepository.getPopularTags(TAGS_LIMIT)
val blacklistTagRegex = appSettings.getSuggestionsTagsBlacklistRegex()
val allTags = historyRepository.getPopularTags(TAGS_LIMIT).filterNot {
blacklistTagRegex?.containsMatchIn(it.title) ?: false
}
if (allTags.isEmpty()) {
return 0
}
@@ -102,6 +105,11 @@ class SuggestionsWorker(appContext: Context, params: WorkerParameters) :
if (appSettings.isSuggestionsExcludeNsfw) {
rawResults.removeAll { it.isNsfw }
}
if (blacklistTagRegex != null) {
rawResults.removeAll {
it.tags.any { x -> blacklistTagRegex.containsMatchIn(x.title) }
}
}
if (rawResults.isEmpty()) {
return 0
}