Test events match filter
This commit is contained in:
parent
42a3bdca68
commit
d06d6afbf7
@ -7,6 +7,7 @@ import { NoteStore } from "./note-collection";
|
||||
import { flatMerge } from "./request-merger";
|
||||
import { BuiltRawReqFilter } from "./request-builder";
|
||||
import { FlatReqFilter, expandFilter } from "./request-expander";
|
||||
import { eventMatchesFilter } from "./request-matcher";
|
||||
|
||||
/**
|
||||
* Tracing for relay query status
|
||||
@ -179,7 +180,11 @@ export class Query implements QueryBase {
|
||||
onEvent(sub: string, e: TaggedNostrEvent) {
|
||||
for (const t of this.#tracing) {
|
||||
if (t.id === sub) {
|
||||
this.feed.add(e);
|
||||
if(t.filters.some(v => eventMatchesFilter(e, v))) {
|
||||
this.feed.add(e);
|
||||
} else {
|
||||
this.#log("Event did not match filter, rejecting %O", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
import { NostrEvent, ReqFilter } from "./nostr";
|
||||
|
||||
export function eventMatchesFilter(ev: NostrEvent, filter: ReqFilter) {
|
||||
if (!(filter.ids?.includes(ev.id) ?? false)) {
|
||||
return false;
|
||||
}
|
||||
if (!(filter.authors?.includes(ev.pubkey) ?? false)) {
|
||||
return false;
|
||||
}
|
||||
if (!(filter.kinds?.includes(ev.kind) ?? false)) {
|
||||
return false;
|
||||
}
|
||||
if (filter.since && ev.created_at < filter.since) {
|
||||
return false;
|
||||
}
|
||||
if (filter.until && ev.created_at > filter.until) {
|
||||
return false;
|
||||
}
|
||||
if (!(filter.ids?.includes(ev.id) ?? true)) {
|
||||
return false;
|
||||
}
|
||||
if (!(filter.authors?.includes(ev.pubkey) ?? true)) {
|
||||
return false;
|
||||
}
|
||||
if (!(filter.kinds?.includes(ev.kind) ?? true)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user