From c075194c3d91c91543660d0cc6a55f4c753b2b1b Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 24 Nov 2021 22:05:02 -0600 Subject: [PATCH] Check for filter applicability with author(s) and kinds --- src/subscription.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/subscription.rs b/src/subscription.rs index eead7e0..7c3b99e 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -102,6 +102,22 @@ impl Subscription { } impl ReqFilter { + // check if the given author matches the query (against author and authors) + fn author_match(&self, author: &str) -> bool { + if self.author.as_ref().map(|v| v == author).unwrap_or(true) { + return true; + } else if self + .authors + .as_ref() + .map(|vs| vs.contains(&author.to_owned())) + .unwrap_or(true) + { + return true; + } else { + return false; + } + } + pub fn interested_in_event(&self, event: &Event) -> bool { // determine if all populated fields in this filter match the provided event. // a filter matches an event if all the populated fields match. @@ -115,6 +131,14 @@ impl ReqFilter { .unwrap_or(true) { false + } else if !self.kind.map(|v| v == event.kind).unwrap_or(true) { + false + } else if !self.author_match(&event.pubkey) { + false + // event: Option, + // pubkey: Option, + // since: Option, + // authors: Option>, } else { true }