feat: 优化规则匹配逻辑,支持通知标题和正文的频道匹配
This commit is contained in:
@@ -200,7 +200,9 @@ object NotificationRuleEngine {
|
|||||||
private fun matchRule(raw: NotificationDb.RawNotification, text: String, rule: Rule): Boolean {
|
private fun matchRule(raw: NotificationDb.RawNotification, text: String, rule: Rule): Boolean {
|
||||||
if (!rule.enabled) return false
|
if (!rule.enabled) return false
|
||||||
val channel = raw.channel ?: ""
|
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) }
|
val keywordHit = rule.keywords.isEmpty() || rule.keywords.any { text.contains(it) }
|
||||||
return channelHit && keywordHit
|
return channelHit && keywordHit
|
||||||
}
|
}
|
||||||
@@ -288,4 +290,3 @@ object NotificationRuleEngine {
|
|||||||
return rule.defaultMerchant ?: "Unknown"
|
return rule.defaultMerchant ?: "Unknown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -249,7 +249,10 @@ const matchRule = (notification, rule) => {
|
|||||||
if (!rule || rule.enabled === false) return false
|
if (!rule || rule.enabled === false) return false
|
||||||
const channel = notification?.channel || ''
|
const channel = notification?.channel || ''
|
||||||
const text = notification?.text || ''
|
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))
|
const keywordHit = !rule.keywords?.length || rule.keywords.some((word) => text.includes(word))
|
||||||
return channelHit && keywordHit
|
return channelHit && keywordHit
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user