Fix anchored notification visibility exceptions

This commit is contained in:
ajp_anton
2026-08-30 23:43:09 +00:00
parent 08f8764c77
commit 30753f1b6a
2 changed files with 16 additions and 4 deletions
@@ -93,19 +93,23 @@ class CompiledVisibilityPolicy(policy: VisibilityPolicy) {
fun isBlocked(notification: VisibilityNotification, surface: NotificationSurface): Boolean {
if (!enabled) return false
val policy = apps[notification.packageName] ?: return false
val matchText = notification.matchText()
val exception = policy.exceptions.firstOrNull { it.pattern.matcher(matchText).find() }
val matchTexts = notification.matchTexts()
val exception = policy.exceptions.firstOrNull { rule ->
matchTexts.any { rule.pattern.matcher(it).find() }
}
return surface in (exception?.blockedSurfaces ?: policy.blockedSurfaces)
}
fun hasExceptions(packageName: String) = apps[packageName]?.exceptions?.isNotEmpty() == true
private fun VisibilityNotification.matchText() = buildList {
private fun VisibilityNotification.matchTexts() = buildList {
add(packageName)
add(key)
listOf(title, text, bigText, subtext, channelId).filterNotNullTo(this)
addAll(messages)
}.joinToString("\n")
}.map(String::trim).filter(String::isNotEmpty).let { fields ->
fields + fields.joinToString("\n")
}
private data class CompiledAppPolicy(
val blockedSurfaces: Set<NotificationSurface>,