diff --git a/src/lib.rs b/src/lib.rs index 5a0b7203..3d25c329 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ mod profile; pub mod relay_pool_manager; mod result; mod route; +mod submgr; mod subscriptions; mod support; mod test_data; diff --git a/src/submgr.rs b/src/submgr.rs new file mode 100644 index 00000000..c8990956 --- /dev/null +++ b/src/submgr.rs @@ -0,0 +1,107 @@ +#![allow(unused)] + +use std::collections::HashMap; + +use enostr::Filter; +use nostrdb; + +/// The Subscription Manager +/// +/// NOTE - This interface wishes it was called Subscriptions but there +/// already is one. Using a lame (but short) placeholder name instead +/// for now ... +/// +/// ``` +/// use crate::SubMgr; +/// +/// let mut submgr = SubMgr::new(); +/// +/// let filter = Filter::new().kinds(vec![1, 2, 3]).build(); +/// let ep = submgr.subscribe(SubSpecBuilder::new(vec![filter]).build())?; +/// loop { +/// match ep.next().await { +/// Ok(nks) => { +/// // process the note keys +/// }, +/// Err(ReevaluateState) => { +/// // not really an error, break out of loop and reevaluate state +/// }, +/// Err(err) => { +/// // something bad happened +/// }, +/// } +/// } +/// submgr.unsubscribe(ep)?; +/// ``` + +pub enum SubError { + ReevaluateState, + InternalError(String), + NdbError(nostrdb::Error), +} + +pub type SubResult = Result; + +pub struct SubId(nostrdb::Subscription); + +pub enum SubConstraint { + OneShot, + AllowedRelays(Vec), + ProhibitedRelays(Vec), + // other constraints as we think of them ... +} + +pub struct SubSpecBuilder { + rmtid: Option, + filters: Vec, + allowed_relays: Vec, + prohibited_relays: Vec, + is_oneshot: bool, +} + +impl SubSpecBuilder { + pub fn new(filters: Vec) -> Self { + unimplemented!(); + } + pub fn rmtid(mut self, id: String) -> Self { + unimplemented!(); + } + // ... more here ... + pub fn build(self) -> SubSpec { + unimplemented!(); + } +} + +pub struct SubSpec { + rmtid: String, + filters: Vec, + constraints: Vec, + allowed_relays: Vec, + prohibited_relays: Vec, + is_oneshot: bool, +} + +pub struct SubMgr { + subs: HashMap, +} + +impl SubMgr { + pub fn subscribe(&mut self, sub: SubSpec) -> SubResult { + unimplemented!(); + } + + pub fn unsubscribe(&mut self, ep: SubEndpoint) -> SubResult<()> { + unimplemented!(); + } +} + +pub struct SubEndpoint { + id: SubId, + // internals omitted ... +} + +impl SubEndpoint { + pub async fn next(&self) -> SubResult> { + unimplemented!(); + } +}