From 03bc1fab18205b3cec263a060cb00a2c6216a793 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 24 Nov 2021 16:22:49 -0600 Subject: [PATCH] API for checking if subscription matches key --- src/event.rs | 5 +++++ src/subscription.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/event.rs b/src/event.rs index 1bdb191..c0827c6 100644 --- a/src/event.rs +++ b/src/event.rs @@ -54,6 +54,11 @@ impl Event { let _e: Event = serde_json::from_str(json)?; Err(Error::EventParseFailed) } + + // check if this event is valid (should be propagated, stored) based on signature. + pub fn is_valid(&self) -> bool { + false + } } #[cfg(test)] diff --git a/src/subscription.rs b/src/subscription.rs index c0f6e38..833d9de 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -1,4 +1,5 @@ use crate::error::{Error, Result}; +use crate::event::Event; use serde::{Deserialize, Deserializer, Serialize}; //use serde_json::json; //use serde_json::Result; @@ -89,6 +90,23 @@ impl Subscription { pub fn get_filter_count(&self) -> usize { self.filters.len() } + pub fn interested_in_event(&self, event: &Event) -> bool { + // loop through every filter, and return true if any match this event. + for f in self.filters.iter() { + if f.interested_in_event(event) { + return true; + } + } + } +} + +impl ReqFilter { + pub fn interested_in_event(&self, event: &Event) -> bool { + // determine if all populated fields in this filter match the provided event. + + todo!(); + true + } } #[cfg(test)]