add NIP-119 compat

This commit is contained in:
Sandwich 2024-11-13 13:20:07 +01:00
parent edc59fbf79
commit 556ea69ddd

View File

@ -101,8 +101,8 @@ export function eventMatchesFilter(ev: NostrEvent, filter: ReqFilter) {
if (!(filter.kinds?.includes(ev.kind) ?? true)) {
return false;
}
const tags = Object.entries(filter).filter(([k]) => k.startsWith("#"));
for (const [k, v] of tags) {
const orTags = Object.entries(filter).filter(([k]) => k.startsWith("#"));
for (const [k, v] of orTags) {
const vargs = v as Array<string>;
for (const x of vargs) {
if (!ev.tags.find(a => a[0] === k.slice(1) && a[1] === x)) {
@ -110,6 +110,13 @@ export function eventMatchesFilter(ev: NostrEvent, filter: ReqFilter) {
}
}
}
const andTags = Object.entries(filter).filter(([k]) => k.startsWith("&"));
for (const [k, v] of andTags) {
const allMatch = (v as string[]).every(x => ev.tags.some(tag => tag[0] === k.slice(1) && tag[1] === x));
if (!allMatch) {
return false;
}
}
return true;
}