Improves efficiency of the filter class for matching and checking errors
This commit is contained in:
+10
-7
@@ -89,14 +89,17 @@ class Filter(
|
||||
if (it.length != 64) Log.e("FilterError", "Invalid author length $it on ${toJson()}")
|
||||
}
|
||||
// tests common tags.
|
||||
tags?.get("p")?.forEach {
|
||||
if (it.length != 64) Log.e("FilterError", "Invalid p-tag length $it on ${toJson()}")
|
||||
if (tags != null) {
|
||||
tags["p"]?.forEach {
|
||||
if (it.length != 64) Log.e("FilterError", "Invalid p-tag length $it on ${toJson()}")
|
||||
}
|
||||
tags["e"]?.forEach {
|
||||
if (it.length != 64) Log.e("FilterError", "Invalid e-tag length $it on ${toJson()}")
|
||||
}
|
||||
tags["a"]?.forEach {
|
||||
if (Address.parse(it) == null) Log.e("FilterError", "Invalid a-tag $it on ${toJson()}")
|
||||
}
|
||||
}
|
||||
tags?.get("e")?.forEach {
|
||||
if (it.length != 64) Log.e("FilterError", "Invalid e-tag length $it on ${toJson()}")
|
||||
}
|
||||
tags?.get("a")?.forEach {
|
||||
if (Address.parse(it) == null) Log.e("FilterError", "Invalid a-tag $it on ${toJson()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -36,7 +36,9 @@ object FilterMatcher {
|
||||
if (kinds?.contains(event.kind) == false) return false
|
||||
if (authors?.contains(event.pubKey) == false) return false
|
||||
tags?.forEach { tag ->
|
||||
if (!event.tags.any { it.first() == tag.key && it[1] in tag.value }) return false
|
||||
val valueSet = tag.value.toSet()
|
||||
// AND between keys, OR between values
|
||||
if (!event.tags.any { it.size > 1 && it[0] == tag.key && it[1] in valueSet }) return false
|
||||
}
|
||||
if (event.createdAt !in (since ?: Long.MIN_VALUE)..(until ?: Long.MAX_VALUE)) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user