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 event;
pub mod proto;
pub mod request;
pub mod subscription;

View File

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