nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 887fc28ab237070d01c0042a6f1d753c8638f5be
parent 294d3b99c32350c9bcb09e14feb2404546e05ce8
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sat, 26 Feb 2022 09:15:45 -0600

fix: until filters in subscriptions now used

Diffstat:
Msrc/subscription.rs | 45+++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/subscription.rs b/src/subscription.rs @@ -214,6 +214,7 @@ impl ReqFilter { // self.id.as_ref().map(|v| v == &event.id).unwrap_or(true) self.ids_match(event) && self.since.map(|t| event.created_at > t).unwrap_or(true) + && self.until.map(|t| event.created_at < t).unwrap_or(true) && self.kind_match(event.kind) && self.authors_match(event) && self.tag_match(event) @@ -322,6 +323,50 @@ mod tests { } #[test] + fn interest_until() -> Result<()> { + // subscription with a filter for ID and time + let s: Subscription = + serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"], "until": 1000}]"#)?; + let e = Event { + id: "abc".to_owned(), + pubkey: "".to_owned(), + created_at: 50, + kind: 0, + tags: Vec::new(), + content: "".to_owned(), + sig: "".to_owned(), + tagidx: None, + }; + assert!(s.interested_in_event(&e)); + Ok(()) + } + + #[test] + fn interest_range() -> Result<()> { + // subscription with a filter for ID and time + let s_in: Subscription = + serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"], "since": 100, "until": 200}]"#)?; + let s_before: Subscription = + serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"], "since": 100, "until": 140}]"#)?; + let s_after: Subscription = + serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"], "since": 160, "until": 200}]"#)?; + let e = Event { + id: "abc".to_owned(), + pubkey: "".to_owned(), + created_at: 150, + kind: 0, + tags: Vec::new(), + content: "".to_owned(), + sig: "".to_owned(), + tagidx: None, + }; + assert!(s_in.interested_in_event(&e)); + assert!(!s_before.interested_in_event(&e)); + assert!(!s_after.interested_in_event(&e)); + Ok(()) + } + + #[test] fn interest_time_and_id() -> Result<()> { // subscription with a filter for ID and time let s: Subscription =