Rename request mod to subscription

This commit is contained in:
Greg Heartsfield 2021-11-24 14:29:31 -06:00
parent 0b7742cfb1
commit 0bac2cbfc8
3 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
pub mod error; pub mod error;
pub mod event; pub mod event;
pub mod proto; pub mod proto;
pub mod request; pub mod subscription;

View File

@ -1,5 +1,5 @@
use crate::error::{Error, Result}; use crate::error::{Error, Result};
use crate::{event, request}; use crate::{event, subscription};
use log::{debug, info}; use log::{debug, info};
use uuid::Uuid; use uuid::Uuid;
@ -31,15 +31,15 @@ impl Proto {
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub enum NostrRawMessage { pub enum NostrRawMessage {
Event(String), Event(String),
Req(String), Sub(String),
Close(String), Close(String),
} }
// A fully parsed request // A fully parsed request
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub enum NostrRequest { pub enum NostrRequest {
Event(event::Event), Ev(event::Event),
Subscription(request::Subscription), Sub(subscription::Subscription),
} }
// Wrap the message in the expected request type // Wrap the message in the expected request type
@ -48,7 +48,7 @@ fn msg_type_wrapper(msg: String) -> Result<NostrRawMessage> {
if msg.starts_with(r#"["EVENT","#) { if msg.starts_with(r#"["EVENT","#) {
Ok(NostrRawMessage::Event(msg)) Ok(NostrRawMessage::Event(msg))
} else if msg.starts_with(r#"["REQ","#) { } else if msg.starts_with(r#"["REQ","#) {
Ok(NostrRawMessage::Req(msg)) Ok(NostrRawMessage::Sub(msg))
} else if msg.starts_with(r#"["CLOSE","#) { } else if msg.starts_with(r#"["CLOSE","#) {
Ok(NostrRawMessage::Close(msg)) Ok(NostrRawMessage::Close(msg))
} else { } else {
@ -61,9 +61,7 @@ pub fn parse_type(msg: String) -> Result<NostrRequest> {
let typ = msg_type_wrapper(msg)?; let typ = msg_type_wrapper(msg)?;
match typ { match typ {
NostrRawMessage::Event(_) => Err(Error::EventParseFailed), NostrRawMessage::Event(_) => Err(Error::EventParseFailed),
NostrRawMessage::Req(m) => Ok(NostrRequest::Subscription(request::Subscription::parse( NostrRawMessage::Sub(m) => Ok(NostrRequest::Sub(subscription::Subscription::parse(&m)?)),
&m,
)?)),
NostrRawMessage::Close(_) => Err(Error::CloseParseFailed), NostrRawMessage::Close(_) => Err(Error::CloseParseFailed),
} }
} }