feat: 优化规则匹配逻辑,支持通知标题和正文的频道匹配

This commit is contained in:
2025-12-03 17:56:02 +08:00
parent 94c1eac279
commit cf760d4001
2 changed files with 7 additions and 3 deletions

View File

@@ -200,7 +200,9 @@ object NotificationRuleEngine {
private fun matchRule(raw: NotificationDb.RawNotification, text: String, rule: Rule): Boolean {
if (!rule.enabled) return false
val channel = raw.channel ?: ""
val channelHit = rule.channels.isEmpty() || rule.channels.any { channel.contains(it) }
// 频道命中:优先用通知来源/标题匹配,必要时回退到正文匹配(兼容 adb shell / 部分厂商改名)
val channelHit =
rule.channels.isEmpty() || rule.channels.any { channel.contains(it) || text.contains(it) }
val keywordHit = rule.keywords.isEmpty() || rule.keywords.any { text.contains(it) }
return channelHit && keywordHit
}
@@ -288,4 +290,3 @@ object NotificationRuleEngine {
return rule.defaultMerchant ?: "Unknown"
}
}

View File

@@ -249,7 +249,10 @@ const matchRule = (notification, rule) => {
if (!rule || rule.enabled === false) return false
const channel = notification?.channel || ''
const text = notification?.text || ''
const channelHit = !rule.channels?.length || rule.channels.some((item) => channel.includes(item))
// 频道命中:优先用通知标题/来源匹配,退而求其次用正文包含匹配(兼容 adb shell / 部分 ROM
const channelHit =
!rule.channels?.length ||
rule.channels.some((item) => channel.includes(item) || text.includes(item))
const keywordHit = !rule.keywords?.length || rule.keywords.some((word) => text.includes(word))
return channelHit && keywordHit
}