diff --git a/src/filter.rs b/src/filter.rs index 691904f..1395b3b 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -8,7 +8,7 @@ use tracing::debug; #[derive(Debug)] pub struct Filter { - data: bindings::ndb_filter, + pub data: bindings::ndb_filter, } impl bindings::ndb_filter { diff --git a/src/ndb.rs b/src/ndb.rs index 7551ec2..6c8d7da 100644 --- a/src/ndb.rs +++ b/src/ndb.rs @@ -81,13 +81,19 @@ impl Ndb { Ok(()) } - pub fn subscribe(&self, filter: Filter) -> Result { + pub fn subscribe(&self, filters: Vec) -> Result { unsafe { - let id = bindings::ndb_subscribe(self.as_ptr(), filter.as_mut_ptr(), 1); + let mut ndb_filters: Vec = + filters.iter().map(|a| a.data).collect(); + let id = bindings::ndb_subscribe( + self.as_ptr(), + ndb_filters.as_mut_ptr(), + filters.len() as i32, + ); if id == 0 { Err(Error::SubscriptionError) } else { - Ok(Subscription { filter, id }) + Ok(Subscription { filters, id }) } } } @@ -260,7 +266,7 @@ mod tests { let mut filter = Filter::new(); filter.kinds(vec![1]); - let sub = ndb.subscribe(filter).expect("sub_id"); + let sub = ndb.subscribe(vec![filter]).expect("sub_id"); let waiter = ndb.wait_for_notes(&sub, 1); ndb.process_event(r#"["EVENT","b",{"id": "702555e52e82cc24ad517ba78c21879f6e47a7c0692b9b20df147916ae8731a3","pubkey": "32bf915904bfde2d136ba45dde32c88f4aca863783999faea2e847a8fafd2f15","created_at": 1702675561,"kind": 1,"tags": [],"content": "hello, world","sig": "2275c5f5417abfd644b7bc74f0388d70feb5d08b6f90fa18655dda5c95d013bfbc5258ea77c05b7e40e0ee51d8a2efa931dc7a0ec1db4c0a94519762c6625675"}]"#).expect("process ok"); let res = waiter.await.expect("await ok"); @@ -279,7 +285,7 @@ mod tests { let mut filter = Filter::new(); filter.kinds(vec![1]); - let sub = ndb.subscribe(filter).expect("sub_id"); + let sub = ndb.subscribe(vec![filter]).expect("sub_id"); ndb.process_event(r#"["EVENT","b",{"id": "702555e52e82cc24ad517ba78c21879f6e47a7c0692b9b20df147916ae8731a3","pubkey": "32bf915904bfde2d136ba45dde32c88f4aca863783999faea2e847a8fafd2f15","created_at": 1702675561,"kind": 1,"tags": [],"content": "hello, world","sig": "2275c5f5417abfd644b7bc74f0388d70feb5d08b6f90fa18655dda5c95d013bfbc5258ea77c05b7e40e0ee51d8a2efa931dc7a0ec1db4c0a94519762c6625675"}]"#).expect("process ok"); // this is too fast, we should have nothing let res = ndb.poll_for_notes(&sub, 1); diff --git a/src/subscription.rs b/src/subscription.rs index abe1153..fc397cd 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -1,6 +1,6 @@ use crate::Filter; pub struct Subscription { - pub filter: Filter, + pub filters: Vec, pub id: u64, }