From 753958659dd552ad07f5d6ddf303d49e111e4af1 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 24 Nov 2021 22:10:42 -0600 Subject: [PATCH] Check event tag filter --- src/event.rs | 13 +++++++++++++ src/subscription.rs | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/event.rs b/src/event.rs index 96fc319..48ecb12 100644 --- a/src/event.rs +++ b/src/event.rs @@ -56,6 +56,19 @@ impl Event { pub fn is_valid(&self) -> bool { false } + // check if given event is referenced in a tag + pub fn event_tag_match(&self, event: &str) -> bool { + for t in self.tags.iter() { + if t.len() == 2 { + if t.get(0).unwrap() == "#e" { + if t.get(1).unwrap() == event { + return true; + } + } + } + } + return false; + } } #[cfg(test)] diff --git a/src/subscription.rs b/src/subscription.rs index 7c3b99e..9e188f3 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -135,6 +135,13 @@ impl ReqFilter { false } else if !self.author_match(&event.pubkey) { false + } else if !self + .event + .as_ref() + .map(|e| event.event_tag_match(e)) + .unwrap_or(true) + { + false // event: Option, // pubkey: Option, // since: Option,